← Back to team overview

yade-users team mailing list archive

[Question #697837]: Problem with CpmStateUpdater

 

New question #697837 on Yade:
https://answers.launchpad.net/yade/+question/697837

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

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.