Skip to content

Commit

Permalink
Updated classdesc to tip of return-restprocess-object-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Sep 10, 2024
1 parent a777ec0 commit cc7825b
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ lib/libecolab$(ECOLIBS_EXT).a: $(OBJS) $(LIBMODS)
# build graphcode objects
-cd graphcode; $(GRAPHCODE_MAKE) libgraphcode.a
-cp -f graphcode/*.h include
ar r $@ $^
ar r $@ $^ graphcode/*.o
ifeq ($(OS),Darwin)
ranlib $@
endif
$(CPLUSPLUS) -shared -Wl,-soname,libecolab$(ECOLIBS_EXT).so.$(SOVERSION) $^ -o lib/libecolab$(ECOLIBS_EXT).so.$(SOVERSION)
$(CPLUSPLUS) -shared -Wl,-soname,libecolab$(ECOLIBS_EXT).so.$(SOVERSION) $^ graphcode/*.o $(LIBS) -o lib/libecolab$(ECOLIBS_EXT).so.$(SOVERSION)
cd lib; ln -sf libecolab$(ECOLIBS_EXT).so.$(SOVERSION) libecolab$(ECOLIBS_EXT).so
cd lib; ln -sf libecolab$(ECOLIBS_EXT).so.$(SOVERSION) ecolab$(ECOLIBS_EXT).so

Expand Down
2 changes: 1 addition & 1 deletion classdesc
Submodule classdesc updated 61 files
+32 −3 Makefile
+36 −0 RESTProcess-allCDs.h
+1 −1 RESTProcessExample/RESTProcessExpected.txt
+105 −66 RESTProcess_base.h
+80 −55 RESTProcess_epilogue.h
+2 −2 Realloc.h
+17 −2 classdesc.h
+8 −12 classdesc_epilogue.h
+16 −0 createCDs.sh
+36 −0 dump-allCDs.h
+2 −2 dump_base.h
+6 −6 dump_epilogue.h
+2 −2 factory.h
+6 −2 function.h
+2 −2 isa_base.h
+2 −2 javaClass.h
+2 −2 javaClass_base.h
+2 −2 javaClass_epilogue.h
+2 −2 javaClass_serialisation.h
+36 −0 json_pack-allCDs.h
+24 −3 json_pack_base.h
+7 −33 json_pack_epilogue.h
+20 −19 multiArray.h
+0 −5 object.h
+36 −0 pack-allCDs.h
+2 −2 pack_base.h
+18 −16 pack_epilogue.h
+2 −2 pack_graph.h
+2 −2 pack_stl.h
+2 −2 pack_stream.h
+2 −2 poly.h
+4 −4 polyAccessJsonPack.h
+4 −4 polyAccessPack.h
+9 −9 polyAccessXMLPack.h
+2 −16 polyBase.h
+7 −2 polyJsonBase.h
+2 −2 polyPackBase.h
+2 −4 polyRESTProcess.h
+2 −2 polyRESTProcessBase.h
+14 −4 polyXMLBase.h
+4 −3 pythonBuffer.h
+2 −2 python_base.h
+2 −2 python_epilogue.h
+36 −0 random_init-allCDs.h
+12 −2 random_init_base.h
+11 −10 random_init_epilogue.h
+2 −2 ref.h
+3 −2 signature.h
+2 −3 stringKeyMap.h
+1 −0 test/c++11/testArray.cc
+0 −1 test/testXMLcd.cc
+0 −1 test/testXMLcd_other.cc
+0 −1 test/testXSDgenerate.cc
+36 −0 typeName-allCDs.h
+4 −2 typeName_epilogue.h
+2 −2 use_mbr_pointers.h
+2 −2 xml_common.h
+36 −0 xml_pack-allCDs.h
+5 −8 xml_pack_base.h
+33 −61 xml_pack_epilogue.h
+6 −8 xml_unpack_base.h
2 changes: 1 addition & 1 deletion graphcode
Submodule graphcode updated 1 files
+12 −11 graphcode.h
1 change: 0 additions & 1 deletion include/ecolab_epilogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ Put this after including all .cd files
*/
#include "classdesc_epilogue.h"
#ifdef GRAPHCODE_H
#include "graphcode.cd"
#endif
30 changes: 29 additions & 1 deletion models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ using array_ns::pcoord;

#include "ecolab_epilogue.h"

using namespace classdesc;

// TODO - move this into main library
namespace
{
Expand Down Expand Up @@ -78,7 +80,6 @@ void ModelData::random_interaction(unsigned conn, double sigma)

void PanmicticModel::generate(unsigned niter)
{
//parallel(args);
if (tstep==0) makeConsistent();
EcolabPoint::generate(niter,*this);
tstep+=niter;
Expand Down Expand Up @@ -390,3 +391,30 @@ bool ConnectionPlot::redraw(int x0, int y0, int width, int height)
return true;
}

void SpatialModel::setGrid(size_t nx, size_t ny)
{
numX=nx; numY=ny;
for (size_t i=0; i<numX; ++i)
for (size_t j=0; j<numY; ++j)
insertObject(makeId(i,j));
}

void SpatialModel::generate(unsigned niter)
{
if (tstep==0) makeConsistent();
for (auto& i: *this) i->as<EcoLabCell>()->generate(niter,*this);
tstep+=niter;
}

void SpatialModel::makeConsistent()
{
// all cells must have same number of species. Pack out with zero density if necessary
unsigned long nsp=0;
for (auto& i: *this) nsp=max(nsp,i->as<EcoLabCell>()->density.size());
#ifdef MPI_SUPPORT
MPI_AllReduce(MPI_IN_PLACE,&nsp,1,MPI_UNSIGNED_LONG,MPI_MAX,MPI_COMM_WORLD);
#endif
for (auto& i: *this)
i->as<EcoLabCell>()->density<<=array<int>(nsp-i->as<EcoLabCell>()->density.size(),0);
ModelData::makeConsistent(nsp);
}
15 changes: 14 additions & 1 deletion models/ecolab_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,20 @@ struct PanmicticModel: public ModelData, public EcolabPoint

struct EcoLabCell: public EcolabPoint, public graphcode::Object<EcoLabCell> {};

struct SpatialModel: public ModelData, public graphcode::Graph<EcoLabCell>
class SpatialModel: public ModelData, public graphcode::Graph<EcoLabCell>
{
size_t numX=1, numY=1;
public:
size_t makeId(size_t x, size_t y) const {return x%numX + numX*(y%numY);}
void setGrid(size_t nx, size_t ny);
graphcode::ObjectPtr<EcoLabCell> cell(size_t x, size_t y) {
return objects[makeId(x,y)];
}
void makeConsistent();
void generate(unsigned niter);
void generate() {generate(1);}
// void condense();
// void mutate();
// void migrate();
};

52 changes: 52 additions & 0 deletions models/spatial_ecolab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from ecolab_model import spatial_ecolab as ecolab
from random import random
# initial number of species
nsp=100

ecolab.repro_min(-0.1)
ecolab.repro_max(0.1)
ecolab.odiag_min(-1e-5)
ecolab.odiag_max(1e-5)
#ecolab.mut_max(1e-4)
ecolab.mut_max(1e-3)
ecolab.sp_sep(0.1)

def randomList(num, min, max):
return [random()*(max-min)+min for i in range(num)]

ecolab.species(range(nsp))

numX=2
numY=2
ecolab.setGrid(numX,numY)
ecolab.partitionObjects()
for i in range(numX):
for j in range(numY):
ecolab.cell(i,j).density(nsp*[100])

ecolab.repro_rate(randomList(nsp, ecolab.repro_min(), ecolab.repro_max()))
ecolab.interaction.diag(randomList(nsp, -1e-3, -1e-3))
ecolab.random_interaction(3,0)

ecolab.interaction.val(randomList(len(ecolab.interaction.val), ecolab.odiag_min(), ecolab.odiag_max()))

ecolab.mutation(nsp*[ecolab.mut_max()])
ecolab.migration(nsp*[1e-5])

from plot import plot

def step():
ecolab.generate()
# ecolab.mutate()
# ecolab.condense()
nsp=len(ecolab.species)
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
# plot('No. species',ecolab.tstep(),nsp)
for i in range(numX):
for j in range(numY):
plot(f'Density({i},{j}',ecolab.tstep(),ecolab.cell(i,j).density()._properties, pens=ecolab.species()._properties)

gui(step)



3 changes: 2 additions & 1 deletion src/cairoSurfaceImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ namespace
if (r==registries().end() || !r->second) throw std::runtime_error("Module: "+module+" not found");
auto rp=r->second->find(object);
if (rp==r->second->end()) throw std::runtime_error("Object: "+object+" not found in "+module);
if (CairoSurface* csurf=dynamic_cast<CairoSurface*>(rp->second->getClassdescObject()))
if (CairoSurface* csurf=
dynamic_cast<CairoSurface*>(const_cast<classdesc::object*>(rp->second->getClassdescObject())))
{
*masterData=new CD(0,master,*csurf);
Tk_ImageChanged(master,0,0,500,500,500,500);
Expand Down

0 comments on commit cc7825b

Please sign in to comment.