← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3846: dummy engine for showing how to derive from FlowEngine + a preliminary version of DFNFlow

 

------------------------------------------------------------
revno: 3846
committer: Bruno Chareyre <bruno.chareyre@xxxxxxxxxxxxxxx>
timestamp: Fri 2014-03-21 19:47:45 +0100
message:
  dummy engine for showing how to derive from FlowEngine + a preliminary version of DFNFlow
added:
  pkg/dem/DFNFlow.cpp
  pkg/dem/DummyFlowEngine.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== added file 'pkg/dem/DFNFlow.cpp'
--- pkg/dem/DFNFlow.cpp	1970-01-01 00:00:00 +0000
+++ pkg/dem/DFNFlow.cpp	2014-03-21 18:47:45 +0000
@@ -0,0 +1,85 @@
+ 
+/*************************************************************************
+*  Copyright (C) 2014 by Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>     *
+*                                                                        *
+*  This program is free software; it is licensed under the terms of the  *
+*  GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+#ifdef FLOW_ENGINE
+
+//keep this #ifdef for commited versions unless you really have stable version that should be compiled by default
+//it will save compilation time for everyone else
+//when you want it compiled, you can pass -DDFNFLOW to cmake, or just uncomment the following line
+// #define DFNFLOW
+#ifdef DFNFLOW
+
+#include <yade/pkg/dem/FlowEngine.hpp>
+
+class DFNCellInfo : public FlowCellInfo
+{
+	public:
+	Real anotherVariable;
+	void anotherFunction() {};
+};
+
+
+class DFNVertexInfo : public FlowVertexInfo {
+	public:
+	//same here if needed
+};
+
+typedef TemplateFlowEngine<DFNCellInfo,DFNVertexInfo> DFNFlowEngineT;
+REGISTER_SERIALIZABLE(DFNFlowEngineT);
+YADE_PLUGIN((DFNFlowEngineT));
+
+class DFNFlowEngine : public DFNFlowEngineT
+{
+	public :
+	void pyTrickPermeability(Real somethingBig);
+	void trickPermeability (RTriangulation::Facet_circulator& facet,Real somethingBig);
+	void trickPermeability (RTriangulation::Finite_edges_iterator& edge,Real somethingBig);
+
+	YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(DFNFlowEngine,DFNFlowEngineT,"documentation here",
+	((Real, myNewAttribute, 0,,"useless example"))
+	,/*DFNFlowEngineT()*/,
+	,
+	.def("trickPermeability",&DFNFlowEngine::pyTrickPermeability,(python::arg("somethingBig")=10.),"change permeability inside a plane")
+	)
+	DECLARE_LOGGER;
+};
+REGISTER_SERIALIZABLE(DFNFlowEngine);
+YADE_PLUGIN((DFNFlowEngine));
+
+void DFNFlowEngine::trickPermeability (RTriangulation::Facet_circulator& facet, Real somethingBig)
+{
+	const RTriangulation& Tri = solver->T[solver->currentTes].Triangulation();
+	const CellHandle& cell1 = facet->first;
+	const CellHandle& cell2 = facet->first->neighbor(facet->second);
+	if ( Tri.is_infinite(cell1) || Tri.is_infinite(cell2)) cerr<<"Infinite cell found in trickPermeability, should be handled somehow, maybe"<<endl;
+	cell1->info().kNorm()[facet->second] = somethingBig;
+	cell2->info().kNorm()[Tri.mirror_index(cell1, facet->second)] = somethingBig;
+}
+
+void DFNFlowEngine::trickPermeability(RTriangulation::Finite_edges_iterator& edge, Real somethingBig)
+{
+	const RTriangulation& Tri = solver->T[solver->currentTes].Triangulation();
+	RTriangulation::Facet_circulator facet1 = Tri.incident_facets(*edge);
+	RTriangulation::Facet_circulator facet0=facet1++;
+	trickPermeability(facet0,somethingBig);
+	while ( facet1!=facet0 ) {trickPermeability(facet1,somethingBig); facet1++;}
+}
+
+
+void DFNFlowEngine::pyTrickPermeability(Real somethingBig)
+{
+	const RTriangulation& Tri = solver->T[solver->currentTes].Triangulation();
+	//We want to change permeability perpendicular to the 10th edge, let's say.
+	//in the end this function should have a loop on all edges I guess
+	FiniteEdgesIterator edge = Tri.finite_edges_begin();
+	for(int k=10; k>0;--k) edge++;
+	trickPermeability(edge,somethingBig);
+}
+
+
+#endif //DFNFLOW
+#endif //FLOWENGINE
\ No newline at end of file

=== added file 'pkg/dem/DummyFlowEngine.cpp'
--- pkg/dem/DummyFlowEngine.cpp	1970-01-01 00:00:00 +0000
+++ pkg/dem/DummyFlowEngine.cpp	2014-03-21 18:47:45 +0000
@@ -0,0 +1,60 @@
+ 
+/*************************************************************************
+*  Copyright (C) 2014 by Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>     *
+*                                                                        *
+*  This program is free software; it is licensed under the terms of the  *
+*  GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+
+// This is an example of how to derive a new FlowEngine with additional data and possibly completely new behaviour.
+// Every functions of the base engine can be overloaded, and new functions can be added
+
+//keep this #ifdef as long as you don't really want to realize a final version publicly, it will save compilation time for everyone else
+//when you want it compiled, you can pass -DDFNFLOW to cmake, or just uncomment the following line
+// #define DUMMYFLOW
+#ifdef DUMMYFLOW
+
+#include <yade/pkg/dem/FlowEngine.hpp>
+
+/// We can add data to the Info types by inheritance
+class DummyCellInfo : public FlowCellInfo
+{
+	public:
+	Real anotherVariable;
+	void anotherFunction() {};
+};
+
+class DummyVertexInfo : public FlowVertexInfo {
+	public:
+	//same here if needed
+};
+
+typedef TemplateFlowEngine<DummyCellInfo,DummyVertexInfo> DummyFlowEngineT;
+REGISTER_SERIALIZABLE(DummyFlowEngineT);
+YADE_PLUGIN((DummyFlowEngineT));
+
+class DummyFlowEngine : public DummyFlowEngineT
+{
+	public :
+	//We can overload every functions of the base engine to make it behave differently
+	//if we overload action() like this, this engine is doing nothing in a standard timestep, it can still have useful functions
+	virtual void action() {};
+	
+	//If a new function is specific to the derived engine, put it here, else go to the base TemplateFlowEngine
+	//if it is useful for everyone
+	void fancyFunction(Real what); {cerr<<"yes, I'm a new function"<<end;}
+
+	YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(DummyFlowEngine,DummyFlowEngineT,"documentation here",
+	((Real, myNewAttribute, 0,,"useless example"))
+	,/*DummyFlowEngineT()*/,
+	,
+	.def("fancyFunction",&DummyFlowEngine::fancyFunction,(python::arg("what")=0),"test function")
+	)
+	DECLARE_LOGGER;
+};
+REGISTER_SERIALIZABLE(DummyFlowEngine);
+YADE_PLUGIN((DummyFlowEngine));
+
+void DummyFlowEngine::fancyFunction(Real what) {cerr<<"yes, I'm a new function"<<end;}
+
+#endif //DummyFLOW
\ No newline at end of file