Blender  V2.93
implicit.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) Blender Foundation
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
26 #include "stdio.h"
27 
28 #include "BLI_utildefines.h"
29 
30 #include "BKE_collision.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 //#define IMPLICIT_SOLVER_EIGEN
37 #define IMPLICIT_SOLVER_BLENDER
38 
39 #define CLOTH_ROOT_FRAME /* enable use of root frame coordinate transform */
40 
41 #define CLOTH_FORCE_GRAVITY
42 #define CLOTH_FORCE_DRAG
43 #define CLOTH_FORCE_SPRING_STRUCTURAL
44 #define CLOTH_FORCE_SPRING_SHEAR
45 #define CLOTH_FORCE_SPRING_BEND
46 #define CLOTH_FORCE_SPRING_GOAL
47 #define CLOTH_FORCE_EFFECTORS
48 
49 //#define IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
50 
51 //#define IMPLICIT_ENABLE_EIGEN_DEBUG
52 
53 struct Implicit_Data;
54 
55 typedef struct ImplicitSolverResult {
56  int status;
57 
59  float error;
61 
63 {
64  printf("%-8.3f", v);
65 }
66 
67 void SIM_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass);
68 void SIM_mass_spring_set_rest_transform(struct Implicit_Data *data, int index, float tfm[3][3]);
69 
71  int index,
72  const float x[3],
73  const float v[3]);
74 void SIM_mass_spring_set_position(struct Implicit_Data *data, int index, const float x[3]);
75 void SIM_mass_spring_set_velocity(struct Implicit_Data *data, int index, const float v[3]);
77  int index,
78  float x[3],
79  float v[3]);
80 void SIM_mass_spring_get_position(struct Implicit_Data *data, int index, float x[3]);
81 void SIM_mass_spring_get_velocity(struct Implicit_Data *data, int index, float v[3]);
82 
83 /* access to modified motion state during solver step */
84 void SIM_mass_spring_get_new_position(struct Implicit_Data *data, int index, float x[3]);
85 void SIM_mass_spring_set_new_position(struct Implicit_Data *data, int index, const float x[3]);
86 void SIM_mass_spring_get_new_velocity(struct Implicit_Data *data, int index, float v[3]);
87 void SIM_mass_spring_set_new_velocity(struct Implicit_Data *data, int index, const float v[3]);
88 
91  int index,
92  const float dV[3]);
94  int index,
95  const float c1[3],
96  const float c2[3],
97  const float dV[3]);
99  int index,
100  const float c1[3],
101  const float dV[3]);
102 
104  float dt,
105  struct ImplicitSolverResult *result);
106 bool SIM_mass_spring_solve_positions(struct Implicit_Data *data, float dt);
108 
109 /* Clear the force vector at the beginning of the time step */
111 /* Fictitious forces introduced by moving coordinate systems */
113  int index,
114  const float acceleration[3],
115  const float omega[3],
116  const float domega_dt[3],
117  float mass);
118 /* Simple uniform gravity force */
120  int index,
121  float mass,
122  const float g[3]);
123 /* Global drag force (velocity damping) */
124 void SIM_mass_spring_force_drag(struct Implicit_Data *data, float drag);
125 /* Custom external force */
127  struct Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3]);
128 /* Wind force, acting on a face (only generates pressure from the normal component) */
130  struct Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3]);
131 /* Arbitrary per-unit-area vector force field acting on a face. */
133  struct Implicit_Data *data, int v1, int v2, int v3, const float (*forcevec)[3]);
134 /* Wind force, acting on an edge */
136  int v1,
137  int v2,
138  float radius1,
139  float radius2,
140  const float (*winvec)[3]);
141 /* Wind force, acting on a vertex */
143  int v,
144  float radius,
145  const float (*winvec)[3]);
146 /* Linear spring force between two points */
148  int i,
149  int j,
150  float restlen,
151  float stiffness_tension,
152  float damping_tension,
153  float stiffness_compression,
154  float damping_compression,
155  bool resist_compress,
156  bool new_compress,
157  float clamp_force);
158 /* Angular spring force between two polygons */
160  int i,
161  int j,
162  int *i_a,
163  int *i_b,
164  int len_a,
165  int len_b,
166  float restang,
167  float stiffness,
168  float damping);
169 /* Bending force, forming a triangle at the base of two structural springs */
171  struct Implicit_Data *data, int i, int j, float restlen, float kb, float cb);
172 /* Angular bending force based on local target vectors */
174  int i,
175  int j,
176  int k,
177  const float target[3],
178  float stiffness,
179  float damping);
180 /* Global goal spring */
182  int i,
183  const float goal_x[3],
184  const float goal_v[3],
185  float stiffness,
186  float damping);
187 
188 float SIM_tri_tetra_volume_signed_6x(struct Implicit_Data *data, int v1, int v2, int v3);
189 float SIM_tri_area(struct Implicit_Data *data, int v1, int v2, int v3);
190 
192  int v1,
193  int v2,
194  int v3,
195  float common_pressure,
196  const float *vertex_pressure,
197  const float weights[3]);
198 
199 /* ======== Hair Volumetric Forces ======== */
200 
201 struct HairGrid;
202 
203 #define MAX_HAIR_GRID_RES 256
204 
206  const float gmin[3],
207  const float gmax[3]);
208 void SIM_hair_volume_free_vertex_grid(struct HairGrid *grid);
210  struct HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3]);
211 
212 void SIM_hair_volume_grid_clear(struct HairGrid *grid);
213 void SIM_hair_volume_add_vertex(struct HairGrid *grid, const float x[3], const float v[3]);
215  const float x1[3],
216  const float v1[3],
217  const float x2[3],
218  const float v2[3],
219  const float x3[3],
220  const float v3[3],
221  const float x4[3],
222  const float v4[3],
223  const float dir1[3],
224  const float dir2[3],
225  const float dir3[3]);
226 
228 
230  float dt,
231  float target_density,
232  float target_strength);
233 #if 0 /* XXX weighting is incorrect, disabled for now */
234 void SIM_hair_volume_vertex_grid_filter_box(struct HairVertexGrid *grid, int kernel_size);
235 #endif
236 
238  const float x[3],
239  float *density,
240  float velocity[3],
241  float velocity_smooth[3],
242  float density_gradient[3],
243  float velocity_gradient[3][3]);
244 
245 /* Effect of fluid simulation grid on velocities.
246  * fluid_factor controls blending between PIC (Particle-in-Cell)
247  * and FLIP (Fluid-Implicit-Particle) methods (0 = only PIC, 1 = only FLIP)
248  */
250  struct HairGrid *grid, const float x[3], const float v[3], float fluid_factor, float r_v[3]);
251 /* XXX Warning: expressing grid effects on velocity as a force is not very stable,
252  * due to discontinuities in interpolated values!
253  * Better use hybrid approaches such as described in
254  * "Detail Preserving Continuum Simulation of Straight Hair"
255  * (McAdams, Selle 2009)
256  */
258  const float x[3],
259  const float v[3],
260  float smoothfac,
261  float pressurefac,
262  float minpressure,
263  float f[3],
264  float dfdx[3][3],
265  float dfdv[3][3]);
266 
267 #ifdef __cplusplus
268 }
269 #endif
#define BLI_INLINE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
void SIM_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float(*winvec)[3])
void SIM_hair_volume_normalize_vertex_grid(struct HairGrid *grid)
void SIM_mass_spring_add_constraint_ndof1(struct Implicit_Data *data, int index, const float c1[3], const float c2[3], const float dV[3])
void SIM_hair_volume_grid_geometry(struct HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3])
void SIM_hair_volume_add_vertex(struct HairGrid *grid, const float x[3], const float v[3])
float SIM_tri_tetra_volume_signed_6x(struct Implicit_Data *data, int v1, int v2, int v3)
void SIM_mass_spring_get_motion_state(struct Implicit_Data *data, int index, float x[3], float v[3])
void SIM_hair_volume_vertex_grid_forces(struct HairGrid *grid, const float x[3], const float v[3], float smoothfac, float pressurefac, float minpressure, float f[3], float dfdx[3][3], float dfdv[3][3])
struct HairGrid * SIM_hair_volume_create_vertex_grid(float cellsize, const float gmin[3], const float gmax[3])
void SIM_mass_spring_add_constraint_ndof0(struct Implicit_Data *data, int index, const float dV[3])
void SIM_mass_spring_force_reference_frame(struct Implicit_Data *data, int index, const float acceleration[3], const float omega[3], const float domega_dt[3], float mass)
void SIM_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3])
bool SIM_hair_volume_solve_divergence(struct HairGrid *grid, float dt, float target_density, float target_strength)
void SIM_mass_spring_set_new_velocity(struct Implicit_Data *data, int index, const float v[3])
bool SIM_mass_spring_force_spring_goal(struct Implicit_Data *data, int i, const float goal_x[3], const float goal_v[3], float stiffness, float damping)
float SIM_tri_area(struct Implicit_Data *data, int v1, int v2, int v3)
void SIM_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass)
void SIM_mass_spring_force_face_extern(struct Implicit_Data *data, int v1, int v2, int v3, const float(*forcevec)[3])
void SIM_mass_spring_get_velocity(struct Implicit_Data *data, int index, float v[3])
void SIM_mass_spring_set_motion_state(struct Implicit_Data *data, int index, const float x[3], const float v[3])
void SIM_hair_volume_free_vertex_grid(struct HairGrid *grid)
void SIM_hair_volume_grid_velocity(struct HairGrid *grid, const float x[3], const float v[3], float fluid_factor, float r_v[3])
bool SIM_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen, float stiffness_tension, float damping_tension, float stiffness_compression, float damping_compression, bool resist_compress, bool new_compress, float clamp_force)
void SIM_mass_spring_get_new_position(struct Implicit_Data *data, int index, float x[3])
bool SIM_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, float restlen, float kb, float cb)
void SIM_mass_spring_apply_result(struct Implicit_Data *data)
void SIM_mass_spring_set_position(struct Implicit_Data *data, int index, const float x[3])
bool SIM_mass_spring_force_spring_bending_hair(struct Implicit_Data *data, int i, int j, int k, const float target[3], float stiffness, float damping)
void SIM_mass_spring_add_constraint_ndof2(struct Implicit_Data *data, int index, const float c1[3], const float dV[3])
void SIM_mass_spring_force_pressure(struct Implicit_Data *data, int v1, int v2, int v3, float common_pressure, const float *vertex_pressure, const float weights[3])
BLI_INLINE void implicit_print_matrix_elem(float v)
Definition: implicit.h:62
void SIM_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
void SIM_mass_spring_get_position(struct Implicit_Data *data, int index, float x[3])
bool SIM_mass_spring_solve_velocities(struct Implicit_Data *data, float dt, struct ImplicitSolverResult *result)
void SIM_mass_spring_set_new_position(struct Implicit_Data *data, int index, const float x[3])
void SIM_mass_spring_force_drag(struct Implicit_Data *data, float drag)
void SIM_mass_spring_clear_constraints(struct Implicit_Data *data)
bool SIM_mass_spring_solve_positions(struct Implicit_Data *data, float dt)
void SIM_mass_spring_get_new_velocity(struct Implicit_Data *data, int index, float v[3])
struct ImplicitSolverResult ImplicitSolverResult
void SIM_mass_spring_set_velocity(struct Implicit_Data *data, int index, const float v[3])
void SIM_hair_volume_add_segment(struct HairGrid *grid, const float x1[3], const float v1[3], const float x2[3], const float v2[3], const float x3[3], const float v3[3], const float x4[3], const float v4[3], const float dir1[3], const float dir2[3], const float dir3[3])
void SIM_hair_volume_grid_interpolate(struct HairGrid *grid, const float x[3], float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
bool SIM_mass_spring_force_spring_angular(struct Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b, float restang, float stiffness, float damping)
void SIM_mass_spring_force_extern(struct Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3])
void SIM_mass_spring_force_gravity(struct Implicit_Data *data, int index, float mass, const float g[3])
void SIM_hair_volume_grid_clear(struct HairGrid *grid)
void SIM_mass_spring_set_rest_transform(struct Implicit_Data *data, int index, float tfm[3][3])
void SIM_mass_spring_clear_forces(struct Implicit_Data *data)
float gmax[3]
Definition: hair_volume.cpp:82
float gmin[3]
Definition: hair_volume.cpp:82
int res[3]
Definition: hair_volume.cpp:81
float cellsize
Definition: hair_volume.cpp:83