Fix: kicked springs caching since it's unused and needs lots of memory
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 18 Sep 2007 19:56:58 +0000 (19:56 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 18 Sep 2007 19:56:58 +0000 (19:56 +0000)
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/implicit.c

index 57975e56cc3e1a2226ff9cc1220ba6c518e2f0c5..194aa06fc3b55411d624bc5e43446a4ad1b5f232 100644 (file)
@@ -518,12 +518,13 @@ void cloth_cache_get_frame(ClothModifierData *clmd, float time)
                                        memcpy(cloth->verts, frame->verts, cloth->numverts*sizeof(ClothVertex));
                                        implicit_set_positions(clmd);
                                }
-                               
+                               /*
                                if(frame->springs)
                                {
                                        // copy ClothSpring struct
                                        memcpy(cloth->springs, frame->springs, cloth->numsprings*sizeof(ClothSpring));
                                }
+                               */
                        }
                }
        }
@@ -546,7 +547,10 @@ void cloth_cache_set_frame(ClothModifierData *clmd, float time)
                        // creat new frame cache
                        frame = (Frame *)MEM_callocN(sizeof(Frame), "cloth frame cache");
                        frame->verts = (ClothVertex *)MEM_callocN(sizeof(ClothVertex)*cloth->numverts, "cloth frame vertex cache");
+                       frame->springs = NULL;
+                       /*
                        frame->springs = (ClothSpring *)MEM_callocN(sizeof(ClothSpring)*cloth->numsprings, "cloth frame spring cache");
+                       */
                        frame->time = newtime;
 
                        // copy ClothVertex struct
@@ -554,13 +558,13 @@ void cloth_cache_set_frame(ClothModifierData *clmd, float time)
                        {
                                memcpy(&frame->verts[i], &cloth->verts[i], sizeof(ClothVertex));
                        }
-                       
+                       /*
                        // copy ClothSpring struct
                        for(i = 0; i < cloth->numsprings; i++)
                        {
                                memcpy(&frame->springs[i], &cloth->springs[i], sizeof(ClothSpring));
                        }
-                       
+                       */
                }
                if(frame)
                {
@@ -600,7 +604,7 @@ void cloth_cache_free(ClothModifierData *clmd, float time)
                                        && (frame->time > newtime)) // do not delete the first frame
                                {
                                        MEM_freeN(frame->verts);
-                                       MEM_freeN(frame->springs);
+                                       // MEM_freeN(frame->springs);
                                        MEM_freeN(frame);       
                                        MEM_freeN(search);
                                        last_search->next = next;
@@ -608,7 +612,7 @@ void cloth_cache_free(ClothModifierData *clmd, float time)
                                else if(clmd->sim_parms.flags & CSIMSETT_FLAG_CCACHE_FREE_ALL) // free COMPLETE cache
                                {
                                        MEM_freeN(frame->verts);
-                                       MEM_freeN(frame->springs);
+                                       // MEM_freeN(frame->springs);
                                        MEM_freeN(frame);       
                                }
                                else
@@ -770,7 +774,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                                        solvers [clmd->sim_parms.solver_type].solver (ob, framenr, clmd, effectors,0,0);
 
                                tend();
-                               // printf("Cloth simulation time: %f\n", (float)tval());
+                               printf("Cloth simulation time: %f\n", (float)tval());
 
                                cloth_cache_set_frame(clmd, framenr);
 
index a6fcf7a9a5e10f715068f04d6de7616256713938..3b19839c77dc54ec822bcd145f8aec98e04a2440 100644 (file)
@@ -947,7 +947,7 @@ int  cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatr
        return conjgrad_loopcount<conjgrad_looplimit;  // true means we reached desired accuracy in given time - ie stable
 }
 /*
-int cg_filtered_pre(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, lfVector *X0, float dt)
+int cg_filtered_pre(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, lfVector *X0, fmatrix3x3 *P, fmatrix3x3 *Pinv, float dt)
 {
 // Solves for unknown X in equation AX=B
 unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100;
@@ -1348,7 +1348,7 @@ void cloth_calc_force(ClothModifierData *clmd, lfVector *lF, lfVector *lX, lfVec
        
        /* calculate and apply spring forces */
 #pragma omp parallel private(i)
-       {
+{
 #pragma omp for nowait
        for(i = 0; i < cloth->numsprings/2; i++)
        {
@@ -1367,7 +1367,8 @@ void cloth_calc_force(ClothModifierData *clmd, lfVector *lF, lfVector *lX, lfVec
                cloth_calc_spring_force(clmd, &springs[i], lF, lX, lV, dFdV, dFdX);
                // }
        }
-#pragma omp for nowait
+} // pragma omp parallel
+       
        for(i = 0; i < cloth->numsprings; i++)
        {
                // only handle active springs
@@ -1393,15 +1394,13 @@ void cloth_calc_force(ClothModifierData *clmd, lfVector *lF, lfVector *lX, lfVec
                        }       
                }
        }
-       }
 }
 
-void simulate_implicit_euler(lfVector *Vnew, lfVector *lX, lfVector *lV, lfVector *lF, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX, float dt, fmatrix3x3 *A, lfVector *B, lfVector *dV, fmatrix3x3 *S, lfVector *z, lfVector *olddV)
+void simulate_implicit_euler(lfVector *Vnew, lfVector *lX, lfVector *lV, lfVector *lF, fmatrix3x3 *dFdV, fmatrix3x3 *dFdX, float dt, fmatrix3x3 *A, lfVector *B, lfVector *dV, fmatrix3x3 *S, lfVector *z, lfVector *olddV, fmatrix3x3 *P, fmatrix3x3 *Pinv)
 {
        unsigned int numverts = dFdV[0].vcount;
 
        lfVector *dFdXmV = create_lfvector(numverts);
-
        initdiag_bfmatrix(A, I);
        zero_lfvector(dV, numverts);
 
@@ -1414,7 +1413,7 @@ void simulate_implicit_euler(lfVector *Vnew, lfVector *lX, lfVector *lV, lfVecto
        itstart();
        
        cg_filtered(dV, A, B, z, S); /* conjugate gradient algorithm to solve Ax=b */
-       // cg_filtered_pre(dV, A, B, z, olddV, dt);
+       // cg_filtered_pre(dV, A, B, z, olddV, P, Pinv, dt);
        
        itend();
        // printf("cg_filtered calc time: %f\n", (float)itval());
@@ -1459,7 +1458,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                
                // calculate 
                cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step );      
-               simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt, id->A, id->B, id->dV, id->S, id->z, id->olddV);
+               simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv);
                
                add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
                
@@ -1521,7 +1520,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                        
                        // calculate 
                        cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step);       
-                       simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt / 2.0f, id->A, id->B, id->dV, id->S, id->z, id->olddV);
+                       simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt / 2.0f, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv);
                }
                
                // itend();