Problem with CpmStateUpdater

Asked by Przemek

Hi everyone,

I have a problem with CpmStateUpdater. I don't know why, but if I want to get the stress tensor (matrix) it is always zero matrix. It looks like, that the updater doesn't launch. Did you have that problem before?
Here is a code (with some modifications)...

CREATE_LOGGER(CpmStateUpdater);
//Real CpmStateUpdater::maxOmega=0.;
//Real CpmStateUpdater::avgRelResidual=0.;

void CpmStateUpdater::update(Scene* _scene)
{
 // declaration of ‘scene’ shadows a member of ‘yade::CpmStateUpdater’ [-Werror=shadow]
 Scene* scene2 = _scene ? _scene : Omega::instance().getScene().get();
 vector<BodyStats> bodyStats;
 bodyStats.resize(scene2->bodies->size());
// assert(bodyStats[0].nCohLinks == 0); // should be initialized by dfault ctor
 //Matrix3r identity = Matrix3r::Identity(); // ??
// Matrix3r incr;
 FOREACH(const shared_ptr<Interaction>& I, *scene2->interactions)
 {
  if (!I) continue;
  if (!I->isReal()) continue;
  shared_ptr<CpmPhys> phys = YADE_PTR_DYN_CAST<CpmPhys>(I->phys);
  if (!phys) continue;
  const Body::id_t id1 = I->getId1(), id2 = I->getId2();
  GenericSpheresContact* geom = YADE_CAST<GenericSpheresContact*>(I->geom.get());

  const Vector3r& n = geom->normal;
  const Real& Fn = phys->Fn;
  const Vector3r& Fs = phys->Fs;
  LOG_FATAL("Fn: "<<Fn<<" ");
  LOG_FATAL("Fs: "<<Fs<<" ");
  LOG_FATAL("n: "<<n<<" ");
  LOG_FATAL("refLength: "<<phys->refLength<<" ");
  //stress[i,j] += geom->refLength*(Fn*n[i]*n[j]+0.5*(Fs[i]*n[j]+Fs[j]*n[i]));
  //stress += geom->refLength*(Fn*outer(n,n)+.5*(outer(Fs,n)+outer(n,Fs)));
  Matrix3r stress = phys->refLength * (Fn * n * n.transpose() + .5 * (Fs * n.transpose() + n * Fs.transpose()));
// LOG_FATAL("Stress: "<<stress<<" ");
// LOG_FATAL("matrix: "<<n*n.transpose()<<" ");

  bodyStats[id1].stress += stress;
  bodyStats[id2].stress += stress;
  //bodyStats[id1].nLinks++;
  //bodyStats[id2].nLinks++;

 }
 // Real tr;
 FOREACH(shared_ptr<Body> B, *scene2->bodies)
 {
  if (!B) continue;
  const Body::id_t& id = B->getId();
  // add damaged contacts that have already been deleted
  CpmState* state = dynamic_cast<CpmState*>(B->state.get());
  if (!state) continue;
  state->stress = bodyStats[id].stress;
  Sphere* sphere = dynamic_cast<Sphere*>(B->shape.get()); // from that ok???
  if (!sphere) continue;
  Real& r = sphere->radius;
  state->stress = bodyStats[id].stress / (4 / 3. * Mathr::PI * r * r * r / .62) * .5;
 }
}

#undef YADE_VERIFY
#undef NNAN
#undef NNANV

And from .hpp file:

class CpmStateUpdater : public PeriodicEngine {
 struct BodyStats {
  Matrix3r stress;
  BodyStats()
          : stress(Matrix3r::Zero())
  {
  }
 };

public:
 virtual void action() override { update(scene); }
 void update(Scene* rb = NULL);
 // clang-format off
 YADE_CLASS_BASE_DOC_ATTRS_CTOR(CpmStateUpdater,PeriodicEngine,"Update :yref:`CpmState` of bodies based on state variables in :yref:`CpmPhys` of interactions with this bod. In particular, bodies' colors and :yref:`CpmState::normDmg` depending on average :yref:`damage<CpmPhys::omega>` of their interactions and number of interactions that were already fully broken and have disappeared is updated. This engine contains its own loop (2 loops, more precisely) over all bodies and should be run periodically to update colors during the simulation, if desired.",
  ,
  initRun=true;
 );
 // clang-format on
 DECLARE_LOGGER;
};
REGISTER_SERIALIZABLE(CpmStateUpdater);

} // namespace yade

BR
Przemek

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

> Here is a code (with some modifications)...

please emphasize somehow what are the changes

Also, what is your Python code (maybe you simply do not call it).

Cheers
Jan

Revision history for this message
Przemek (przemekn) said :
#2

Hi,

You have right... I don't lauch this updater in my python code. My fault ;)
Thanks a lot!

BR
Przemek

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Needs information' state without activity for the last 15 days.