invalid pointer

Asked by Yor1

Hello,

I want to modify the scripts c++ JointedCohesiveFroctionalPM.cpp and .hpp to calculate the dissiped energy.
After writing the modifications, i compile yade with "make install" in directory "YADE/sources/build".
When i run the code, i obtain this error message:
*** Error in `/usr/bin/python': free(): invalid pointer: 0x0a0f1718 ***
Abandon (core dumped)

this is the modified JointedCohesiveFroctionalPM.cpp script:

/* LucScholtes2010 */

#include"JointedCohesiveFrictionalPM.hpp"
#include<core/Scene.hpp>
#include<pkg/dem/ScGeom.hpp>
#include<core/Omega.hpp>

YADE_PLUGIN((JCFpmMat)(JCFpmState)(JCFpmPhys)(Ip2_JCFpmMat_JCFpmMat_JCFpmPhys)(Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM));

/********************** Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM ****************************/
CREATE_LOGGER(Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM);

bool Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM::go(shared_ptr<IGeom>& ig, shared_ptr<IPhys>& ip, Interaction* contact){

 const int &id1 = contact->getId1();
 const int &id2 = contact->getId2();
 ScGeom* geom = static_cast<ScGeom*>(ig.get());
 JCFpmPhys* phys = static_cast<JCFpmPhys*>(ip.get());

 Body* b1 = Body::byId(id1,scene).get();
 Body* b2 = Body::byId(id2,scene).get();

 Real Dtensile=phys->FnMax/phys->kn;

 string fileCracks = "cracks_"+Key+".txt";
        //string
 /// Defines the interparticular distance used for computation
 Real D = 0;

 /*this is for setting the equilibrium distance between all cohesive elements in the first contact detection*/
 if ( contact->isFresh(scene) ) {
   phys->normalForce = Vector3r::Zero();
   phys->shearForce = Vector3r::Zero();
   if ((smoothJoint) && (phys->isOnJoint)) {
     phys->jointNormal = geom->normal.dot(phys->jointNormal)*phys->jointNormal; //to set the joint normal colinear with the interaction normal
     phys->jointNormal.normalize();
     phys->initD = std::abs((b1->state->pos - b2->state->pos).dot(phys->jointNormal)); // to set the initial gap as the equilibrium gap
   } else {
     phys->initD = geom->penetrationDepth;
   }
 }

 if ( smoothJoint && phys->isOnJoint ) {
   if ( phys->more || ( phys-> jointCumulativeSliding > (2*min(geom->radius1,geom->radius2)) ) ) {
     if (!neverErase) return false;
     else {
       phys->shearForce = Vector3r::Zero();
       phys->normalForce = Vector3r::Zero();
       phys->isCohesive =0;
       phys->FnMax = 0;
       phys->FsMax = 0;
       return true; // do we need this? -> yes if it ends the loop (avoid the following calculations)
       }
   } else {
     D = phys->initD - std::abs((b1->state->pos - b2->state->pos).dot(phys->jointNormal));
   }
 } else {
   D = geom->penetrationDepth - phys->initD;
 }

 phys->crackJointAperture = D<0? -D : 0.; // for DFNFlow

 /* Determination of interaction */
 if (D < 0) { //spheres do not touch
   if (!phys->isCohesive) {
     if (!neverErase) return false;
     else {
       phys->shearForce = Vector3r::Zero();
       phys->normalForce = Vector3r::Zero();
       phys->isCohesive =0;
       phys->FnMax = 0;
       phys->FsMax = 0;
       return true; // do we need this? not sure -> yes, it ends the loop (avoid the following calculations)
     }
   }

   if ( phys->isCohesive && (phys->FnMax>0) && (std::abs(D)>Dtensile) ) {

     // update body state with the number of broken bonds
     JCFpmState* st1=dynamic_cast<JCFpmState*>(b1->state.get());
     JCFpmState* st2=dynamic_cast<JCFpmState*>(b2->state.get());
     st1->tensBreak+=1;
     st2->tensBreak+=1;
     st1->tensBreakRel+=1.0/st1->noIniLinks;
     st2->tensBreakRel+=1.0/st2->noIniLinks;

     totalCracksE=totalCracksE+0.5*( ((phys->normalForce.norm()*phys->normalForce.norm())/phys->kn) + ((phys->shearForce.norm()*phys->shearForce.norm())/phys->ks) ); // written by Jabrane Hamdi
         // create a text file to record properties of the broken bond (iteration, position, type (tensile), cross section, contact normal orientation and dissipated energy)
     if (recordCracks) {
       Real scalarNF=phys->normalForce.norm();
       Real scalarSF=phys->shearForce.norm();
       std::ofstream file (fileCracks.c_str(), !cracksFileExist ? std::ios::trunc : std::ios::app);
       if(file.tellp()==0){ file <<"i p0 p1 p2 t s norm0 norm1 norm2 e"<<endl; }
       Vector3r crackNormal=Vector3r::Zero();
       if ((smoothJoint) && (phys->isOnJoint)) { crackNormal=phys->jointNormal; } else {crackNormal=geom->normal;}
       file << boost::lexical_cast<string> ( scene->iter )<<" "<< boost::lexical_cast<string> ( geom->contactPoint[0] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[1] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[2] ) <<" "<< 0 <<" "<< boost::lexical_cast<string> ( 0.5*(geom->radius1+geom->radius2) ) <<" "<< boost::lexical_cast<string> ( crackNormal[0] ) <<" "<< boost::lexical_cast<string> ( crackNormal[1] ) <<" "<< boost::lexical_cast<string> ( crackNormal[2] ) <<" "<< boost::lexical_cast<string> ( 0.5*( ((scalarNF*scalarNF)/phys->kn) + ((scalarSF*scalarSF)/phys->ks) ) ) << endl;
     }
     cracksFileExist=true;

     /// Timos
     if (!neverErase) return false;
     else {
       phys->shearForce = Vector3r::Zero();
       phys->normalForce = Vector3r::Zero();
       phys->isCohesive =0;
       phys->FnMax = 0;
       phys->FsMax = 0;
       phys->isBroken = true;
       return true; // do we need this? -> yes, it ends the loop (avoid the following calculations)
     }
   }
 }

 /* NormalForce */
 Real Fn = 0;
 Fn = phys->kn*D;

 /* ShearForce */
 Vector3r& shearForce = phys->shearForce;
 Real jointSliding=0;

 /* Energy calculated by particles sliding written by Jabrane Hamdi */
 totalSlipE=0;

 if ( smoothJoint && phys->isOnJoint ) {

   /// incremental formulation (OK?)
   Vector3r relativeVelocity = (b2->state->vel - b1->state->vel); // angVel are not taken into account as particles on joint don't rotate ????
   Vector3r slidingVelocity = relativeVelocity - phys->jointNormal.dot(relativeVelocity)*phys->jointNormal;
   Vector3r incrementalSliding = slidingVelocity*scene->dt;
   shearForce -= phys->ks*incrementalSliding;

   jointSliding = incrementalSliding.norm();
   phys->jointCumulativeSliding += jointSliding;

 } else {

   shearForce = geom->rotate(phys->shearForce);
   const Vector3r& incrementalShear = geom->shearIncrement();
   shearForce -= phys->ks*incrementalShear;

 }

 /* Mohr-Coulomb criterion */
 Real maxFs = phys->FsMax + Fn*phys->tanFrictionAngle;
 Real scalarShearForce = shearForce.norm();

 if (scalarShearForce > maxFs) {

   if (!phys->isCohesive) {

     // why these lines? Can we really have purely normal compressive loading? I guess yes...
     if (scalarShearForce != 0) {

       Vector3r trialForce=shearForce;

// /// static friction sliding
       shearForce*=maxFs/scalarShearForce;
       /// energy dissipated by particles sliding written by Jabrane Hamdi
       totalSlipE=totalSlipE+((1./phys->ks)*(trialForce-shearForce))/*plastic disp*/ .dot(shearForce)/*active force*/;

// /// dynamic friction sliding on joint - TEST
// if ( phys->isOnJoint ) {
// shearForce*=(Fn*std::tan(5*180/Mathr::PI))/scalarShearForce;
// } else {
// shearForce*=maxFs/scalarShearForce;
// }

       /// create a text file to record properties of the slipping contact (iteration, position, type (slip), cross section, contact normal orientation and dissipated energy)
       int geometryIndex1 = b1->shape->getClassIndex();
       int geometryIndex2 = b2->shape->getClassIndex();

       if ( (recordSlips) && (maxFs!=0) && (geometryIndex1==geometryIndex2) ) { // avoid non working forces -> one of the 2 tests should be enough, right
  std::ofstream file (fileCracks.c_str(), !cracksFileExist ? std::ios::trunc : std::ios::app);
  if(file.tellp()==0){ file <<"i p0 p1 p2 t s norm0 norm1 norm2 e"<<endl; }
  Vector3r crackNormal=Vector3r::Zero();
  if ((smoothJoint) && (phys->isOnJoint)) { crackNormal=phys->jointNormal; } else {crackNormal=geom->normal;}
  file << boost::lexical_cast<string> ( scene->iter )<<" "<< boost::lexical_cast<string> ( geom->contactPoint[0] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[1] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[2] ) <<" "<< 2 <<" "<< boost::lexical_cast<string> ( 0.5*(geom->radius1+geom->radius2) ) <<" "<< boost::lexical_cast<string> ( crackNormal[0] ) <<" "<< boost::lexical_cast<string> ( crackNormal[1] ) <<" "<< boost::lexical_cast<string> ( crackNormal[2] ) <<" "<< boost::lexical_cast<string> ( ((1./phys->ks)*(trialForce-shearForce))/*plastic disp*/ .dot(shearForce)/*active force*/ ) << endl;
       }
       cracksFileExist=true;

     } else {
       shearForce=Vector3r::Zero();
     }

     if ((smoothJoint) && (phys->isOnJoint)) {phys->dilation=phys->jointCumulativeSliding*phys->tanDilationAngle-D; phys->initD+=(jointSliding*phys->tanDilationAngle);}

   }

   // take into account shear cracking -> are those lines critical? -> TODO testing with and without
   if (phys->isCohesive) {

     // update body state with the number of broken bonds
     JCFpmState* st1=dynamic_cast<JCFpmState*>(b1->state.get());
     JCFpmState* st2=dynamic_cast<JCFpmState*>(b2->state.get());
     st1->shearBreak+=1;
     st2->shearBreak+=1;
     st1->shearBreakRel+=1.0/st1->noIniLinks;
     st2->shearBreakRel+=1.0/st2->noIniLinks;

     // create a text file to record properties of the broken bond (iteration, position, type (shear), cross section, contact normal orientation and dissipated energy)
     if (recordCracks) {
       Real scalarNF=phys->normalForce.norm();
       Real scalarSF=phys->shearForce.norm();
       std::ofstream file (fileCracks.c_str(), !cracksFileExist ? std::ios::trunc : std::ios::app);
       if(file.tellp()==0){ file <<"i p0 p1 p2 t s norm0 norm1 norm2 e"<<endl; }
       Vector3r crackNormal=Vector3r::Zero();
       if ((smoothJoint) && (phys->isOnJoint)) { crackNormal=phys->jointNormal; } else {crackNormal=geom->normal;}
       file << boost::lexical_cast<string> ( scene->iter )<<" "<< boost::lexical_cast<string> ( geom->contactPoint[0] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[1] ) <<" "<< boost::lexical_cast<string> ( geom->contactPoint[2] ) <<" "<< 1 <<" "<< boost::lexical_cast<string> ( 0.5*(geom->radius1+geom->radius2) ) <<" "<< boost::lexical_cast<string> ( crackNormal[0] ) <<" "<< boost::lexical_cast<string> ( crackNormal[1] ) <<" "<< boost::lexical_cast<string> ( crackNormal[2] ) <<" "<< boost::lexical_cast<string> ( 0.5*( ((scalarNF*scalarNF)/phys->kn) + ((scalarSF*scalarSF)/phys->ks) ) ) << endl;
     }
     cracksFileExist=true;

// // option 1: set the contact properties to friction if in compression, delete contact if in tension
// phys->isBroken = true;
// phys->isCohesive = 0;
// phys->FnMax = 0;
// phys->FsMax = 0;
// // shearForce *= Fn*phys->tanFrictionAngle/scalarShearForce; // now or at the next timestep?
// if ( D < 0 ) { // spheres do not touch
// if (!neverErase) return false;
// else {
// phys->shearForce = Vector3r::Zero();
// phys->normalForce = Vector3r::Zero();
// return true; // do we need this? not sure -> yes, it ends the loop (avoid the following calculations)
// }
// }

     // option 2: delete contact whatever compressive or tensile state
     if (!neverErase) return false;
     else {
       phys->shearForce = Vector3r::Zero();
       phys->normalForce = Vector3r::Zero();
       phys->isCohesive =0;
       phys->FnMax = 0;
       phys->FsMax = 0;
       phys->isBroken = true;
       return true; // do we need this? -> yes, it ends the loop (avoid the following calculations)
     }

   }
 }

 /* Apply forces */
 if ((smoothJoint) && (phys->isOnJoint)) { phys->normalForce = Fn*phys->jointNormal; } else { phys->normalForce = Fn*geom->normal; }

 Vector3r f = phys->normalForce + shearForce;

 /// applyForceAtContactPoint computes torque also and, for now, we don't want rotation for particles on joint (some errors in calculation due to specific geometry)
  //applyForceAtContactPoint(f, geom->contactPoint, I->getId2(), b2->state->pos, I->getId1(), b1->state->pos, scene);
 scene->forces.addForce (id1,-f);
 scene->forces.addForce (id2, f);

 // simple solution to avoid torque computation for particles interacting on a smooth joint
 if ( (phys->isOnJoint)&&(smoothJoint) ) return true;

 /// those lines are needed if rootBody->forces.addForce and rootBody->forces.addMoment are used instead of applyForceAtContactPoint -> NOTE need to check for accuracy!!!
 scene->forces.addTorque(id1,(geom->radius1-0.5*geom->penetrationDepth)* geom->normal.cross(-f));
 scene->forces.addTorque(id2,(geom->radius2-0.5*geom->penetrationDepth)* geom->normal.cross(-f));
 return true;

}
/********************** Ip2_JCFpmMat_JCFpmMat_JCFpmPhys ****************************/
CREATE_LOGGER(Ip2_JCFpmMat_JCFpmMat_JCFpmPhys);

void Ip2_JCFpmMat_JCFpmMat_JCFpmPhys::go(const shared_ptr<Material>& b1, const shared_ptr<Material>& b2, const shared_ptr<Interaction>& interaction){

 /* avoid updates of interaction if it already exists */
 if( interaction->phys ) return;

 ScGeom* geom=dynamic_cast<ScGeom*>(interaction->geom.get());
 assert(geom);

 const shared_ptr<JCFpmMat>& yade1 = YADE_PTR_CAST<JCFpmMat>(b1);
 const shared_ptr<JCFpmMat>& yade2 = YADE_PTR_CAST<JCFpmMat>(b2);
 JCFpmState* st1=dynamic_cast<JCFpmState*>(Body::byId(interaction->getId1(),scene)->state.get());
 JCFpmState* st2=dynamic_cast<JCFpmState*>(Body::byId(interaction->getId2(),scene)->state.get());

 shared_ptr<JCFpmPhys> contactPhysics(new JCFpmPhys());

 /* From material properties */
 Real E1 = yade1->young;
 Real E2 = yade2->young;
 Real v1 = yade1->poisson;
 Real v2 = yade2->poisson;
 Real f1 = yade1->frictionAngle;
 Real f2 = yade2->frictionAngle;
 Real SigT1 = yade1->tensileStrength;
 Real SigT2 = yade2->tensileStrength;
 Real Coh1 = yade1->cohesion;
 Real Coh2 = yade2->cohesion;

 /* From interaction geometry */
 Real R1= geom->radius1;
 Real R2= geom->radius2;
 contactPhysics->crossSection = Mathr::PI*pow(min(R1,R2),2);

 /* Pass values to JCFpmPhys. In case of a "jointed" interaction, the following values will be replaced by other ones later (in few if(){} blocks)*/

 // frictional properties
 contactPhysics->kn = 2.*E1*R1*E2*R2/(E1*R1+E2*R2);
 if ( (v1==0)&&(v2==0) )
   contactPhysics->ks = 0;
 else
   contactPhysics->ks = 2.*E1*R1*v1*E2*R2*v2/(E1*R1*v1+E2*R2*v2);
 contactPhysics->tanFrictionAngle = std::tan(std::min(f1,f2));

 // cohesive properties
 ///to set if the contact is cohesive or not
 if ( ((cohesiveTresholdIteration < 0) || (scene->iter < cohesiveTresholdIteration)) && (std::min(SigT1,SigT2)>0 || std::min(Coh1,Coh2)>0) && (yade1->type == yade2->type)){
   contactPhysics->isCohesive=true;
   st1->noIniLinks++;
   st2->noIniLinks++;
 }

 if ( contactPhysics->isCohesive ) {
   contactPhysics->FnMax = std::min(SigT1,SigT2)*contactPhysics->crossSection;
   contactPhysics->FsMax = std::min(Coh1,Coh2)*contactPhysics->crossSection;
 }

 /// +++ Jointed interactions ->NOTE: geom->normal is oriented from 1 to 2 / jointNormal from plane to sphere
 if ( st1->onJoint && st2->onJoint )
 {
  if ( (((st1->jointNormal1.cross(st2->jointNormal1)).norm()<0.1) && (st1->jointNormal1.dot(st2->jointNormal1)<0)) || (((st1->jointNormal1.cross(st2->jointNormal2)).norm()<0.1) && (st1->jointNormal1.dot(st2->jointNormal2)<0)) || (((st1->jointNormal1.cross(st2->jointNormal3)).norm()<0.1) && (st1->jointNormal1.dot(st2->jointNormal3)<0)) )
  {
    contactPhysics->isOnJoint = true;
    contactPhysics->jointNormal = st1->jointNormal1;
  }
  else if ( (((st1->jointNormal2.cross(st2->jointNormal1)).norm()<0.1) && (st1->jointNormal2.dot(st2->jointNormal1)<0)) || (((st1->jointNormal2.cross(st2->jointNormal2)).norm()<0.1) && (st1->jointNormal2.dot(st2->jointNormal2)<0)) || (((st1->jointNormal2.cross(st2->jointNormal3)).norm()<0.1) && (st1->jointNormal2.dot(st2->jointNormal3)<0)) )
  {
    contactPhysics->isOnJoint = true;
    contactPhysics->jointNormal = st1->jointNormal2;
  }
  else if ( (((st1->jointNormal3.cross(st2->jointNormal1)).norm()<0.1) && (st1->jointNormal3.dot(st2->jointNormal1)<0)) || (((st1->jointNormal3.cross(st2->jointNormal2)).norm()<0.1) && (st1->jointNormal3.dot(st2->jointNormal2)<0)) || (((st1->jointNormal3.cross(st2->jointNormal3)).norm()<0.1) && (st1->jointNormal3.dot(st2->jointNormal3)<0)) )
  {
    contactPhysics->isOnJoint = true;
    contactPhysics->jointNormal = st1->jointNormal3;
  }
  else if ( (st1->joint>3 || st2->joint>3) && ( ( ((st1->jointNormal1.cross(st2->jointNormal1)).norm()>0.1) && ((st1->jointNormal1.cross(st2->jointNormal2)).norm()>0.1) && ((st1->jointNormal1.cross(st2->jointNormal3)).norm()>0.1) ) || ( ((st1->jointNormal2.cross(st2->jointNormal1)).norm()>0.1) && ((st1->jointNormal2.cross(st2->jointNormal2)).norm()>0.1) && ((st1->jointNormal2.cross(st2->jointNormal3)).norm()>0.1) ) || ( ((st1->jointNormal3.cross(st2->jointNormal1)).norm()>0.1) && ((st1->jointNormal3.cross(st2->jointNormal2)).norm()>0.1) && ((st1->jointNormal3.cross(st2->jointNormal3)).norm()>0.1) ) ) ) { contactPhysics->isOnJoint = true; contactPhysics->more = true; contactPhysics->jointNormal = geom->normal; }
 }

 ///to specify joint properties
 if ( contactPhysics->isOnJoint ) {
   Real jf1 = yade1->jointFrictionAngle;
   Real jf2 = yade2->jointFrictionAngle;
   Real jkn1 = yade1->jointNormalStiffness;
   Real jkn2 = yade2->jointNormalStiffness;
   Real jks1 = yade1->jointShearStiffness;
   Real jks2 = yade2->jointShearStiffness;
   Real jdil1 = yade1->jointDilationAngle;
   Real jdil2 = yade2->jointDilationAngle;
   Real jcoh1 = yade1->jointCohesion;
   Real jcoh2 = yade2->jointCohesion;
   Real jSigT1 = yade1->jointTensileStrength;
   Real jSigT2 = yade2->jointTensileStrength;

   contactPhysics->tanFrictionAngle = std::tan(std::min(jf1,jf2));

   //contactPhysics->kn = jointNormalStiffness*2.*R1*R2/(R1+R2); // very first expression from Luc
   //contactPhysics->kn = (jkn1+jkn2)/2.0*2.*R1*R2/(R1+R2); // after putting jointNormalStiffness in material
   contactPhysics->kn = ( jkn1 + jkn2 ) /2.0 * contactPhysics->crossSection; // for a size independant expression
   contactPhysics->ks = ( jks1 + jks2 ) /2.0 * contactPhysics->crossSection; // for a size independant expression

   contactPhysics->tanDilationAngle = std::tan(std::min(jdil1,jdil2));

   ///to set if the contact is cohesive or not
   if ( ((cohesiveTresholdIteration < 0) || (scene->iter < cohesiveTresholdIteration)) && (std::min(jcoh1,jcoh2)>0 || std::min(jSigT1,jSigT2)>0) ) {
     contactPhysics->isCohesive=true;
     st1->noIniLinks++;
     st2->noIniLinks++;
   }
   else { contactPhysics->isCohesive=false; contactPhysics->FnMax=0; contactPhysics->FsMax=0; }

   if ( contactPhysics->isCohesive ) {
    contactPhysics->FnMax = std::min(jSigT1,jSigT2)*contactPhysics->crossSection;
    contactPhysics->FsMax = std::min(jcoh1,jcoh2)*contactPhysics->crossSection;
   }
 }
 interaction->phys = contactPhysics;
}

JCFpmPhys::~JCFpmPhys(){}

and this is the modified JointedCohesiveFroctionalPM.hpp script:

/* lucScholtes2010 */

#pragma once

#include<pkg/common/ElastMat.hpp>
#include<pkg/common/Dispatching.hpp>
#include<pkg/common/NormShearPhys.hpp>
#include<pkg/dem/ScGeom.hpp>

/** This class holds information associated with each body state*/
class JCFpmState: public State {
 YADE_CLASS_BASE_DOC_ATTRS_CTOR(JCFpmState,State,"JCFpm state information about each body.",
  ((int,tensBreak,0,,"Number of tensile breakages. [-]"))
  ((int,shearBreak,0,,"Number of shear breakages. [-]"))
  ((int,noIniLinks,0,,"Number of initial cohesive interactions. [-]"))
  ((Real,tensBreakRel,0,,"Relative number (in [0;1], compared with :yref:`noIniLinks<JCFpmState.noIniLinks>`) of tensile breakages. [-]"))
  ((Real,shearBreakRel,0,,"Relative number (in [0;1], compared with :yref:`noIniLinks<JCFpmState.noIniLinks>`) of shear breakages. [-]"))
  ((bool,onJoint,false,,"Identifies if the particle is on a joint surface."))
  ((int,joint,0,,"Indicates the number of joint surfaces to which the particle belongs (0-> no joint, 1->1 joint, etc..). [-]"))
  ((Vector3r,jointNormal1,Vector3r::Zero(),,"Specifies the normal direction to the joint plane 1. Rk: the ideal here would be to create a vector of vector wich size is defined by the joint integer (as much joint normals as joints). However, it needs to make the pushback function works with python since joint detection is done through a python script. lines 272 to 312 of cpp file should therefore be adapted. [-]"))
  ((Vector3r,jointNormal2,Vector3r::Zero(),,"Specifies the normal direction to the joint plane 2. [-]"))
  ((Vector3r,jointNormal3,Vector3r::Zero(),,"Specifies the normal direction to the joint plane 3. [-]"))
                ,
  createIndex();
 );
 REGISTER_CLASS_INDEX(JCFpmState,State);
};
REGISTER_SERIALIZABLE(JCFpmState);

/** This class holds information associated with each body */
class JCFpmMat: public FrictMat {
   public:
  virtual shared_ptr<State> newAssocState() const { return shared_ptr<State>(new JCFpmState); }
  virtual bool stateTypeOk(State* s) const { return (bool)dynamic_cast<JCFpmState*>(s); }

 YADE_CLASS_BASE_DOC_ATTRS_CTOR(JCFpmMat,FrictMat,"Possibly jointed, cohesive frictional material, for use with other JCFpm classes",
  ((Real,cohesion,0.,,"Defines the maximum admissible tangential force in shear, for Fn=0, in the matrix (:yref:`FsMax<JCFpmPhys.FsMax>` = cohesion * :yref:`crossSection<JCFpmPhys.crossSection>`). [Pa]"))
  ((Real,jointCohesion,0.,,"Defines the :yref:`maximum admissible tangential force in shear<JCFpmPhys.FsMax>`, for Fn=0, on the joint surface. [Pa]"))
  ((Real,jointDilationAngle,0,,"Defines the dilatancy of the joint surface (only valid for :yref:`smooth contact logic<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.smoothJoint>`). [rad]"))
  ((Real,jointFrictionAngle,-1,,"Defines Coulomb friction on the joint surface. [rad]"))
  ((Real,jointNormalStiffness,0.,,"Defines the normal stiffness on the joint surface. [Pa/m]"))
  ((Real,jointShearStiffness,0.,,"Defines the shear stiffness on the joint surface. [Pa/m]"))
  ((Real,jointTensileStrength,0.,,"Defines the :yref:`maximum admissible normal force in traction<JCFpmPhys.FnMax>` on the joint surface. [Pa]"))
  ((int,type,0,,"If particles of two different types interact, it will be with friction only (no cohesion).[-]"))
  ((Real,tensileStrength,0.,,"Defines the maximum admissible normal force in traction in the matrix (:yref:`FnMax<JCFpmPhys.FnMax>` = tensileStrength * :yref:`crossSection<JCFpmPhys.crossSection>`). [Pa]"))
  ,
  createIndex();
 );
 REGISTER_CLASS_INDEX(JCFpmMat,FrictMat);
};
REGISTER_SERIALIZABLE(JCFpmMat);

/** This class holds information associated with each interaction */
class JCFpmPhys: public NormShearPhys {
 public:
  virtual ~JCFpmPhys();

  YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(JCFpmPhys,NormShearPhys,"Representation of a single interaction of the JCFpm type, storage for relevant parameters",
   ((Real,initD,0,,"equilibrium distance for interacting particles. Computed as the interparticular distance at first contact detection."))
   ((bool,isCohesive,false,,"If false, particles interact in a frictional way. If true, particles are bonded regarding the given :yref:`cohesion<JCFpmMat.cohesion>` and :yref:`tensile strength<JCFpmMat.tensileStrength>` (or their jointed variants)."))
   ((bool,more,false,,"specifies if the interaction is crossed by more than 3 joints. If true, interaction is deleted (temporary solution)."))
   ((bool,isOnJoint,false,,"defined as true when both interacting particles are :yref:`on joint<JCFpmState.onJoint>` and are in opposite sides of the joint surface. In this case, mechanical parameters of the interaction are derived from the ''joint...'' material properties of the particles. Furthermore, the normal of the interaction may be re-oriented (see :yref:`Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.smoothJoint`)."))
   ((Real,tanFrictionAngle,0,,"tangent of Coulomb friction angle for this interaction (auto. computed). [-]"))
   ((Real,crossSection,0,,"crossSection=pi*Rmin^2. [m2]"))
   ((Real,FnMax,0,,"positiv value computed from :yref:`tensile strength<JCFpmMat.tensileStrength>` (or joint variant) to define the maximum admissible normal force in traction: Fn >= -FnMax. [N]"))
   ((Real,FsMax,0,,"computed from :yref:`cohesion<JCFpmMat.cohesion>` (or jointCohesion) to define the maximum admissible tangential force in shear, for Fn=0. [N]"))
   ((Vector3r,jointNormal,Vector3r::Zero(),,"normal direction to the joint, deduced from e.g. :yref:`<JCFpmState.jointNormal1>`."))
   ((Real,jointCumulativeSliding,0,,"sliding distance for particles interacting on a joint. Used, when :yref:`<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.smoothJoint>` is true, to take into account dilatancy due to shearing. [-]"))
   ((Real,tanDilationAngle,0,,"tangent of the angle defining the dilatancy of the joint surface (auto. computed from :yref:`JCFpmMat.jointDilationAngle`). [-]"))
   ((Real,dilation,0,,"defines the normal displacement in the joint after sliding treshold. [m]"))
   ((bool,isBroken,false,,"flag for broken interactions"))
   ((Real,crackJointAperture,0,,"Relative displacement between 2 spheres (in case of a crack it is equivalent of the crack aperture)"))
   ,
   createIndex();
   ,
  );
  DECLARE_LOGGER;
  REGISTER_CLASS_INDEX(JCFpmPhys,NormShearPhys);
};
REGISTER_SERIALIZABLE(JCFpmPhys);

/** 2d functor creating InteractionPhysics (Ip2) taking JCFpmMat and JCFpmMat of 2 bodies, returning type JCFpmPhys */
class Ip2_JCFpmMat_JCFpmMat_JCFpmPhys: public IPhysFunctor{
 public:
  virtual void go(const shared_ptr<Material>& pp1, const shared_ptr<Material>& pp2, const shared_ptr<Interaction>& interaction);

  FUNCTOR2D(JCFpmMat,JCFpmMat);
  DECLARE_LOGGER;

  YADE_CLASS_BASE_DOC_ATTRS(Ip2_JCFpmMat_JCFpmMat_JCFpmPhys,IPhysFunctor,"Converts 2 :yref:`JCFpmMat` instances to one :yref:`JCFpmPhys` instance, with corresponding parameters.",
   ((int,cohesiveTresholdIteration,1,,"should new contacts be cohesive? If strictly negativ, they will in any case. If positiv, they will before this iter, they won't afterward."))
  );

};
REGISTER_SERIALIZABLE(Ip2_JCFpmMat_JCFpmMat_JCFpmPhys);

/** 2d functor creating the interaction law (Law2) based on SphereContactGeometry (ScGeom) and JCFpmPhys of 2 bodies, returning type JointedCohesiveFrictionalPM */
class Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM: public LawFunctor{
 public:
  virtual bool go(shared_ptr<IGeom>& _geom, shared_ptr<IPhys>& _phys, Interaction* I);
  FUNCTOR2D(ScGeom,JCFpmPhys);

  YADE_CLASS_BASE_DOC_ATTRS(Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM,LawFunctor,"Interaction law for cohesive frictional material, e.g. rock, possibly presenting joint surfaces, that can be mechanically described with a smooth contact logic [Ivars2011]_ (implemented in Yade in [Scholtes2012]_). See examples/jointedCohesiveFrictionalPM for script examples. Joint surface definitions (through stl meshes or direct definition with gts module) are illustrated there.",
   ((string,Key,"",,"string specifying the name of saved file 'cracks___.txt', when :yref:`recordCracks<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.recordCracks>` is true."))
   ((bool,cracksFileExist,false,,"if true (and if :yref:`recordCracks<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.recordCracks>`), data are appended to an existing 'cracksKey' text file; otherwise its content is reset."))
   ((bool,smoothJoint,false,,"if true, interactions of particles belonging to joint surface (:yref:`JCFpmPhys.isOnJoint`) are handled according to a smooth contact logic [Ivars2011]_, [Scholtes2012]_."))
   ((bool,recordCracks,false,,"if true, data about cohesive interactions that break are stored in a text file cracksKey.txt (see :yref:`Key<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.Key>` and :yref:`cracksFileExist<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.cracksFileExist>`). It contains 9 columns: the break iteration, the 3 coordinates of the contact point, the type (1 means shear break, while 0 corresponds to tensile break), the ''cross section'' (mean radius of the 2 spheres), the 3 coordinates of the contact normal and the energy released."))
   ((bool,recordSlips,false,,"if true, data about frictional interactions that slip are stored in a text file cracksKey.txt."))
   ((bool,neverErase,false,,"Keep interactions even if particles go away from each other (only in case another constitutive law is in the scene"))
   ((Real,totalSlipE,0.,,"calculate the sum of the energy dissipated by particles sliding we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi
   ((Real,totalCracksE,0.,,"calculate the sum of the energy dissipated by particles contact broken we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi
  );
  DECLARE_LOGGER;
};
REGISTER_SERIALIZABLE(Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM);

Jabrane

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Yor1
Solved:
Last query:
Last reply:
Revision history for this message
Anton Gladky (gladky-anton) said :
#1

Hi Jabrane,

it is difficult to analyze this code. Please send the diffs, e.g. lines,
which were modified by you. Also please compile Yade in debug
mode, so you will hopefully get some more information during the
crash.

Regards

Anton

Revision history for this message
Yor1 (jabrane-hamdi) said :
#2

Hi Anton,

The lines which modified by me are:

*line 89 in JointCohesiveFrictionalPM.cpp
totalCracksE=totalCracksE+0.5*( ((phys->normalForce.norm()*phys->normalForce.norm())/phys->kn) + ((phys->shearForce.norm()*phys->shearForce.norm())/phys->ks) ); // written by Jabrane Hamdi

*line 124 in JointCohesiveFrictionalPM.cpp
/* Energy calculated by particles sliding written by Jabrane Hamdi */
 totalSlipE=0;

* line 162 in JointCohesiveFrictionalPM.cpp
 /// energy dissipated by particles sliding written by Jabrane Hamdi
       totalSlipE=totalSlipE+((1./phys->ks)*(trialForce-shearForce))/*plastic disp*/ .dot(shearForce)/*active force*/;

Best regards
Jabrane
*line 112 in JointCohesiveFrictionalPM.hpp
((Real,totalSlipE,0.,,"calculate the sum of the energy dissipated by particles sliding we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi

*line 113 in JointCohesiveFrictionalPM.hpp
((Real,totalCracksE,0.,,"calculate the sum of the energy dissipated by particles contact broken we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi

Revision history for this message
Yor1 (jabrane-hamdi) said :
#3

Hello Anton,

How can we compile yade with debug mode ?
When i compile yade i use this command:
"make install" in this directory YADE/sources/build
is this what you mean by compiling yade with debug mode ?

Best regards
Jabrane

Revision history for this message
Jérôme Duriez (jduriez) said :
#4

Hello,

"make install" is just the command to launch compilation. How compilation is done (e.g. with debug mode or not) depends on what you defined in the previous "cmake ..." step.

If you want to compile in debug mode, you have to define as true the corresponding option during this cmake step (-DDEBUG = ON namely)

See https://yade-dem.org/doc/installation.html#compilation

Revision history for this message
Jan Stránský (honzik) said :
#5

Hi Jabrane,
could you please also provide us with Python script you use for Yade run?
Thanks
Jan

2015-12-10 18:07 GMT+01:00 Jérôme Duriez <
<email address hidden>>:

> Question #277532 on Yade changed:
> https://answers.launchpad.net/yade/+question/277532
>
> Jérôme Duriez proposed the following answer:
> Hello,
>
> "make install" is just the command to launch compilation. How
> compilation is done (e.g. with debug mode or not) depends on what you
> defined in the previous "cmake ..." step.
>
> If you want to compile in debug mode, you have to define as true the
> corresponding option during this cmake step (-DDEBUG = ON namely)
>
> See https://yade-dem.org/doc/installation.html#compilation
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Yor1 (jabrane-hamdi) said :
#6

Hi Jan,

I think that the problem is not in the python script because when i write the symbolic link of yade in the
terminal i have the same error message:
*** Error in `/usr/bin/python': free(): invalid pointer: 0x0a0f1718 ***
Abandon (core dumped)

This is my python script:

from yade import ymport, utils , plot
import math

PACKING='X1Y2Z1_20k'
OUT=PACKING+'_compressionTest'

#### Simulation Control
DAMP=0.4 # numerical damping
saveData=100 # data record interval
iterMax=350000 # maximum number of iteration (to be adjusted)
saveVTK=10000 # Vtk files record interval

#### Boundary Conditions
confinement=-1e6
#uniaxial_stress=-1e6
delta_stress=-1e6
stress_max=-205e6
strainRate=-0.01

intR=1.4450546
DENS=4000
YOUNG=65e9
FRICT=10
ALPHA=0.4
TENS=8e6
COH=160e6

def sphereMat(): return JCFpmMat(type=1,density=DENS,young=YOUNG,poisson = ALPHA,frictionAngle=radians(FRICT),tensileStrength=TENS,cohesion=COH)
def wallMat(): return JCFpmMat(type=0,density=DENS,young=YOUNG,frictionAngle=radians(0))

O.bodies.append(ymport.text(PACKING+'.spheres',scale=1.,shift=Vector3(0,0,0),material=sphereMat))

dim=utils.aabbExtrema()
xinf=dim[0][0]
xsup=dim[1][0]
X=xsup-xinf
yinf=dim[0][1]
ysup=dim[1][1]
Y=ysup-yinf
zinf=dim[0][2]
zsup=dim[1][2]
Z=zsup-zinf

R=0
Rmax=0
numSpheres=0.
for o in O.bodies:
 if isinstance(o.shape,Sphere):
   numSpheres+=1
   R+=o.shape.radius
   if o.shape.radius>Rmax:
     Rmax=o.shape.radius
Rmean=R/numSpheres

O.reset()

mn,mx=Vector3(xinf+0.1*Rmean,yinf+0.1*Rmean,zinf+0.1*Rmean),Vector3(xsup-0.1*Rmean,ysup-0.1*Rmean,zsup-0.1*Rmean)
walls=utils.aabbWalls(oversizeFactor=1.5,extrema=(mn,mx),thickness=min(X,Y,Z)/100.,material=wallMat)
wallIds=O.bodies.append(walls)

beam=O.bodies.append(ymport.text(PACKING+'.spheres',scale=1.,shift=Vector3(0,0,0),material=sphereMat))

for o in O.bodies:
 if isinstance(o.shape,Sphere):
   o.shape.color=(0.7,0.5,0.3)

O.engines=[
        ForceResetter(),
        InsertionSortCollider([Bo1_Box_Aabb(),Bo1_Sphere_Aabb(aabbEnlargeFactor=intR,label='Saabb')]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(interactionDetectionFactor=intR,label='SSgeom'),Ig2_Box_Sphere_ScGeom()],
  [Ip2_JCFpmMat_JCFpmMat_JCFpmPhys(cohesiveTresholdIteration=1,label='interactionPhys')],
  [Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM(recordCracks=True,Key=OUT,label='interactionLaw')]
 ),
        TriaxialStressController(internalCompaction=False,label='triax'),
        GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=10,timestepSafetyCoefficient=0.4, defaultDt=0.1*utils.PWaveTimeStep()),
        NewtonIntegrator(damping=DAMP,label="newton"),
        PyRunner(iterPeriod=int(saveData),initRun=True,command='recorder()',label='data'),
        VTKRecorder(iterPeriod=int(saveVTK),initRun=True,fileName=OUT+'-',recorders=['spheres','jcfpm','cracks'],Key=OUT,label='vtk')
]
plot.plots={'i':('s1','s2','s3')}
plot.plot()

#---------------- SIMULATION STARTS HERE

#### manage interaction detection factor during the first timestep and then set default interaction range ((cf. A DEM model for soft and hard rock, Scholtes & Donze, JMPS 2013))
O.step();
### initializes the interaction detection factor
SSgeom.interactionDetectionFactor=-1.
Saabb.aabbEnlargeFactor=-1.

#### coordination number verification and reinforcement of boundary particles
numSSlinks=0
numCohesivelinks=0
numFrictionalLinks=0
for i in O.interactions:
    if not i.isReal : continue
    if isinstance(O.bodies[i.id1].shape,Sphere) and isinstance(O.bodies[i.id2].shape,Sphere):
     numSSlinks+=1
     if i.phys.isCohesive :
      numCohesivelinks+=1
     else :
      numFrictionalLinks+=1

print "nbSpheres=", numSpheres," | coordination number =", 2.0*numCohesivelinks/numSpheres

#### APPLYING ISOTROPIC LOADING
triax.stressMask=7
triax.goal1=confinement
triax.goal2=confinement
triax.goal3=confinement
triax.max_vel=0.01

while 1:
  if confinement==0:
    O.run(1000,True) # to stabilize the system
    break
  O.run(100,True)
  unb=unbalancedForce()
  #note: triax.stress(k) returns a stress vector, so we need to keep only the normal component
  meanS=abs(triax.stress(triax.wall_right_id)[0]+triax.stress(triax.wall_top_id)[1]+triax.stress(triax.wall_front_id)[2])/3
  print 'unbalanced force:',unb,' mean stress: ',meanS
  if unb<0.005 and abs(meanS-abs(confinement))/abs(confinement)<0.001:
    O.run(1000,True) # to stabilize the system
    e10=triax.strain[0]
    e20=triax.strain[1]
    e30=triax.strain[2]
    break
O.bodies[wallIds[2]].mat.frictionAngle=radians(30)
O.bodies[wallIds[3]].mat.frictionAngle=radians(30)

triax.stressMask=7
triax.goal1=confinement
triax.goal2=confinement
triax.goal3=confinement
triax.max_vel=1

for i in range(0,int(-1e-6*stress_max)):
 if ( abs(triax.goal2) < abs(stress_max) ):
  O.run(200,True)
  triax.goal2+=delta_stress

triax.stressMask=5
triax.goal1=confinement
triax.goal2=strainRate
triax.goal3=confinement
triax.max_vel=1

O.run(iterMax)

Revision history for this message
Yor1 (jabrane-hamdi) said :
#7

Hello,

When i compile the code, there is not error and this is a good thing.
But the problem is that the new variables defined in JointedCohesiveFroctionalPM.hpp (totalSlipE and totalCracksE)
can not be called in python scripts when i write "label.totalSlipE=interactionLaw.totalSlipE" and "interactionLaw.totalCracksE".

Best regards.
Jabrane.

Revision history for this message
Jérôme Duriez (jduriez) said :
#8

Did you define these variables in the YADE_CLASS_... function of the hpp ?

It is required for variables to be accessed / modified through python:
https://yade-dem.org/doc/prog.html#yade-class-base-doc-macro-family

Revision history for this message
Yor1 (jabrane-hamdi) said :
#9

Yes i define the variables like this in JointedCohesiveFroctionalPM.hpp :

class Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM: public LawFunctor{
 public:
  virtual bool go(shared_ptr<IGeom>& _geom, shared_ptr<IPhys>& _phys, Interaction* I);
  FUNCTOR2D(ScGeom,JCFpmPhys);

  YADE_CLASS_BASE_DOC_ATTRS(Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM,LawFunctor,"Interaction law for cohesive frictional material, e.g. rock, possibly presenting joint surfaces, that can be mechanically described with a smooth contact logic [Ivars2011]_ (implemented in Yade in [Scholtes2012]_). See examples/jointedCohesiveFrictionalPM for script examples. Joint surface definitions (through stl meshes or direct definition with gts module) are illustrated there.",
   ((string,Key,"",,"string specifying the name of saved file 'cracks___.txt', when :yref:`recordCracks<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.recordCracks>` is true."))
   ((bool,cracksFileExist,false,,"if true (and if :yref:`recordCracks<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.recordCracks>`), data are appended to an existing 'cracksKey' text file; otherwise its content is reset."))
   ((bool,smoothJoint,false,,"if true, interactions of particles belonging to joint surface (:yref:`JCFpmPhys.isOnJoint`) are handled according to a smooth contact logic [Ivars2011]_, [Scholtes2012]_."))
   ((bool,recordCracks,false,,"if true, data about cohesive interactions that break are stored in a text file cracksKey.txt (see :yref:`Key<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.Key>` and :yref:`cracksFileExist<Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM.cracksFileExist>`). It contains 9 columns: the break iteration, the 3 coordinates of the contact point, the type (1 means shear break, while 0 corresponds to tensile break), the ''cross section'' (mean radius of the 2 spheres), the 3 coordinates of the contact normal and the energy released."))
   ((bool,recordSlips,false,,"if true, data about frictional interactions that slip are stored in a text file cracksKey.txt."))
   ((bool,neverErase,false,,"Keep interactions even if particles go away from each other (only in case another constitutive law is in the scene"))
   ((Real,totalSlipE,0.,,"calculate the sum of the energy dissipated by particles sliding we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi
   ((Real,totalCracksE,0.,,"calculate the sum of the energy dissipated by particles contact broken we can get the value in the recorder through interactionLaw.totalSlipE")) // written by Jabrane Hamdi
  );

Revision history for this message
Anton Gladky (gladky-anton) said :
#10

2015-12-10 17:26 GMT+01:00 Yor1 <email address hidden>:
> "make install" in this directory YADE/sources/build

It is a bad idea to have a build directory inside a source. Please do
it separately.

Anton

Revision history for this message
Anton Gladky (gladky-anton) said :
#11

2015-12-11 11:02 GMT+01:00 Yor1 <email address hidden>:
> I think that the problem is not in the python script because when i write the symbolic link of yade

If you use symbolic link please be sure you are using correct libyade.
I would recommend you to use an absolute path with debugging purpose.

Please check your code, can it be you have somewhere division by zero?

Anton

Revision history for this message
Yor1 (jabrane-hamdi) said :
#12

Hello Anton,

The problem is in cmake, in fact when i write in the terminal:
"make install"

i have this error message at the end :

 Install configuration: "Release"
-- Installing: /usr/local/bin/yade-2015-04-08.git-f3818b4-batch
CMake Error at cmake_install.cmake:44 (FILE):
  file INSTALL cannot copy file
  "/home/hamdi/YADE/sources/build/bins/yade-2015-04-08.git-f3818b4-batch" to
  "/usr/local/bin/yade-2015-04-08.git-f3818b4-batch".

Revision history for this message
Anton Gladky (gladky-anton) said :
#13

Do you have write permission in target folder?

Revision history for this message
Yor1 (jabrane-hamdi) said :
#14

when i have the error, i just write "make install".
Now, i don't have the error because i wrote "sudo make install" and it solves my
problem.

Jabrane

Revision history for this message
Anton Gladky (gladky-anton) said :
#15

> Now, i don't have the error because i wrote "sudo make install" and it solves my
problem.

It is a dangerous solution. I would recommend you to use "-DCMAKE_INSTALL_PREFIX=" option without "sudo".

Anton