[Bf-blender-cvs] [c63a1a9a3ae] soc-2020-soft-body: changed youngs to input exponent
mattoverby
noreply at git.blender.org
Wed Jul 29 01:14:21 CEST 2020
Commit: c63a1a9a3ae42e9b28b73057e5735fbdfa787d0e
Author: mattoverby
Date: Tue Jul 28 18:14:17 2020 -0500
Branches: soc-2020-soft-body
https://developer.blender.org/rBc63a1a9a3ae42e9b28b73057e5735fbdfa787d0e
changed youngs to input exponent
===================================================================
M extern/softbody/src/admmpd_solver.cpp
M extern/softbody/src/admmpd_types.h
M intern/softbody/admmpd_api.cpp
M release/scripts/startup/bl_ui/properties_physics_softbody.py
M source/blender/blenkernel/intern/softbody.c
M source/blender/makesdna/DNA_object_force_types.h
M source/blender/makesrna/intern/rna_object_force.c
===================================================================
diff --git a/extern/softbody/src/admmpd_solver.cpp b/extern/softbody/src/admmpd_solver.cpp
index d524a783b8b..6302384f388 100644
--- a/extern/softbody/src/admmpd_solver.cpp
+++ b/extern/softbody/src/admmpd_solver.cpp
@@ -65,37 +65,31 @@ int Solver::solve(
ConjugateGradients cg;
cg.init_solve(options,data);
+ double dt = options->timestep_s;
- int substeps = std::max(1,options->substeps);
- double dt = options->timestep_s / double(substeps);
+ // Init the solve which computes
+ // quantaties like M_xbar and makes sure
+ // the variables are sized correctly.
+ init_solve(mesh,options,data,collision);
+ // Begin solver loop
int iters = 0;
- for (int i=0; i<substeps; ++i)
+ for (; iters < options->max_admm_iters; ++iters)
{
- // Init the solve which computes
- // quantaties like M_xbar and makes sure
- // the variables are sized correctly.
- init_solve(mesh,options,data,collision);
+ // Update ADMM z/u
+ solve_local_step(options,data);
- // Begin solver loop
- for (; iters < options->max_admm_iters; ++iters)
- {
- // Update ADMM z/u
- solve_local_step(options,data);
-
- // Collision detection and linearization
- update_collisions(options,data,collision);
+ // Collision detection and linearization
+ update_collisions(options,data,collision);
- // Solve Ax=b s.t. Px=q and Cx=d
- cg.solve(options,data,collision);
+ // Solve Ax=b s.t. Px=q and Cx=d
+ cg.solve(options,data,collision);
- } // end solver iters
+ } // end solver iters
- // Update velocity (if not static solve)
- if (dt > 0.0)
- data->v.noalias() = (data->x-data->x_start)*(1.0/dt);
-
- }
+ // Update velocity (if not static solve)
+ if (dt > 0.0)
+ data->v.noalias() = (data->x-data->x_start)*(1.0/dt);
return iters;
} // end solve
@@ -120,8 +114,7 @@ void Solver::init_solve(
// - update velocity with explicit forces
// - update pin constraint matrix (goal positions)
// - set x init guess
- double dt = std::max(0.0, options->timestep_s) /
- double(std::max(1, options->substeps));
+ double dt = std::max(0.0, options->timestep_s);
data->x_start = data->x;
for (int i=0; i<nx; ++i)
{
@@ -356,8 +349,7 @@ void Solver::update_global_matrix(
if (data->P.cols() != nx*3)
throw_err("update_global_matrix","no pin matrix");
- double dt = options->timestep_s /
- double(std::max(1,options->substeps));
+ double dt = options->timestep_s;
double dt2 = dt*dt;
if (dt2 < 0) // static solve
dt2 = 1.0;
diff --git a/extern/softbody/src/admmpd_types.h b/extern/softbody/src/admmpd_types.h
index 0d3016f4aeb..55a15f3c44f 100644
--- a/extern/softbody/src/admmpd_types.h
+++ b/extern/softbody/src/admmpd_types.h
@@ -23,7 +23,6 @@ template <typename T> using RowSparseMatrix = Eigen::SparseMatrix<T,Eigen::RowMa
struct Options {
double timestep_s;
- int substeps;
int max_admm_iters;
int max_cg_iters;
int max_gs_iters;
@@ -41,7 +40,6 @@ struct Options {
Eigen::Vector3d grav;
Options() :
timestep_s(1.0/24.0),
- substeps(1),
max_admm_iters(30),
max_cg_iters(10),
max_gs_iters(100),
diff --git a/intern/softbody/admmpd_api.cpp b/intern/softbody/admmpd_api.cpp
index 9eef0552b5a..c599f59391d 100644
--- a/intern/softbody/admmpd_api.cpp
+++ b/intern/softbody/admmpd_api.cpp
@@ -70,11 +70,10 @@ static inline void options_from_object(Object *ob, admmpd::Options *op)
op->mult_pk = std::max(0.f,std::min(1.f,sb->admmpd_goalstiff));
op->mult_ck = std::max(0.f,std::min(1.f,sb->admmpd_collisionstiff));
op->density_kgm3 = std::max(1.f,sb->admmpd_density_kgm3);
- op->youngs = std::max(0.f,sb->admmpd_youngs);
+ op->youngs = std::pow(10.f, std::max(0.f,sb->admmpd_youngs_exp));
op->poisson = std::max(0.f,std::min(0.499f,sb->admmpd_poisson));
op->floor = sb->admmpd_floor_z;
op->self_collision = sb->admmpd_self_collision;
- op->substeps = sb->admmpd_substeps;
switch(sb->admmpd_material)
{
@@ -263,7 +262,7 @@ int admmpd_init(ADMMPDInterfaceData *iface, Object *ob, float (*vertexCos)[3], i
iface->idata->data = std::make_unique<admmpd::SolverData>();
float fps = std::min(1000.f,std::max(1.f,iface->in_framerate));
admmpd::Options *op = iface->idata->options.get();
- op->timestep_s = 1.0/fps;
+ op->timestep_s = (1.0/fps) / float(std::max(1,sb->admmpd_substeps));
options_from_object(ob,op);
// Initialize the mesh
@@ -405,7 +404,7 @@ void admmpd_copy_to_bodypoint_and_object(ADMMPDInterfaceData *iface, BodyPoint *
int admmpd_solve(ADMMPDInterfaceData *iface, Object *ob)
{
- if (iface==NULL || ob==NULL)
+ if (iface==NULL || ob==NULL || ob->soft==NULL)
{
strcpy_error(iface, "NULL input");
return 0;
@@ -422,11 +421,15 @@ int admmpd_solve(ADMMPDInterfaceData *iface, Object *ob)
try
{
- admmpd::Solver().solve(
+ int substeps = std::max(1,ob->soft->admmpd_substeps);
+ for (int i=0; i<substeps; ++i)
+ {
+ admmpd::Solver().solve(
iface->idata->mesh.get(),
iface->idata->options.get(),
iface->idata->data.get(),
iface->idata->collision.get());
+ }
}
catch(const std::exception &e)
{
diff --git a/release/scripts/startup/bl_ui/properties_physics_softbody.py b/release/scripts/startup/bl_ui/properties_physics_softbody.py
index f42cc5132e0..0880e9e59aa 100644
--- a/release/scripts/startup/bl_ui/properties_physics_softbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_softbody.py
@@ -91,7 +91,7 @@ class PHYSICS_PT_softbody_object(PhysicButtonsPanel, Panel):
elif softbody.solver_mode=='ADMMPD':
col = flow.column()
- col.prop(softbody, "admmpd_youngs")
+ col.prop(softbody, "admmpd_youngs_exp")
col.prop(softbody, "admmpd_poisson")
col.prop(softbody, "admmpd_material")
col.prop(softbody, "admmpd_density_kgm3")
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 30e1d10437b..9765f2cec37 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -3142,7 +3142,7 @@ SoftBody *sbNew(Scene *scene)
sb->admmpd_self_collision = 0;
sb->admmpd_material = ADMMPD_MATERIAL_ARAP;
sb->admmpd_converge_eps = 1e-6;
- sb->admmpd_youngs = 1000000;
+ sb->admmpd_youngs_exp = 6;
sb->admmpd_poisson = 0.399;
sb->admmpd_density_kgm3 = 1522;
sb->admmpd_collisionstiff = 1;
diff --git a/source/blender/makesdna/DNA_object_force_types.h b/source/blender/makesdna/DNA_object_force_types.h
index 89de313e511..572c948ff13 100644
--- a/source/blender/makesdna/DNA_object_force_types.h
+++ b/source/blender/makesdna/DNA_object_force_types.h
@@ -221,7 +221,7 @@ typedef struct SoftBody {
int admmpd_self_collision; // 0 or 1
int admmpd_material; // see enum
float admmpd_converge_eps; // convergence epsilon
- float admmpd_youngs; // Youngs mod
+ float admmpd_youngs_exp; // Youngs mod exponent
float admmpd_poisson; // Poisson ratio
float admmpd_density_kgm3; // unit-density of object
float admmpd_collisionstiff; // 0 to 1
diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c
index 33cf029ae17..3b0dde384a9 100644
--- a/source/blender/makesrna/intern/rna_object_force.c
+++ b/source/blender/makesrna/intern/rna_object_force.c
@@ -1855,10 +1855,10 @@ static void rna_def_softbody(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Tolerance", "Solver tolerance");
RNA_def_property_update(prop, 0, "rna_softbody_update");
- prop = RNA_def_property(srna, "admmpd_youngs", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "admmpd_youngs");
- RNA_def_property_range(prop, 1.f, 1e+10f);
- RNA_def_property_ui_text(prop, "Young's modulus", "Material stiffness");
+ prop = RNA_def_property(srna, "admmpd_youngs_exp", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "admmpd_youngs_exp");
+ RNA_def_property_range(prop, 1.f, 10.f);
+ RNA_def_property_ui_text(prop, "Young's mod", "Young's modulus exponent: 10^(n)");
RNA_def_property_update(prop, 0, "rna_softbody_update");
prop = RNA_def_property(srna, "admmpd_poisson", PROP_FLOAT, PROP_NONE);
More information about the Bf-blender-cvs
mailing list