00001
00011 #include "SimObjectPopulation.h"
00012 #include "SimObject.h"
00013
00014 shared_ptr<SimObjectPopulation> SimObjectPopulation::record( const SimObjectFactory &recFactory, const port_t src_port)
00015 {
00016 SimObject::ID::Vector rec_id_vec(new vector< SimObject::ID::Packed >(size()));
00017
00018 for (int i = 0; i < (int)size() ; ++i) {
00019 (*rec_id_vec)[i] = net->record((*id_vec)[i], src_port, recFactory);
00020 }
00021
00022 return shared_ptr<SimObjectPopulation>( new SimObjectPopulation(*net, rec_id_vec) );
00023 }
00024
00025 shared_ptr<SimObjectPopulation> SimObjectPopulation::record(const SimObjectFactory &recFactory, const string field )
00026 {
00027 SimObject::ID::Vector rec_id_vec(new vector< SimObject::ID::Packed>(size()));
00028
00029 for (int i = 0; i < (int)size() ; ++i) {
00030 (*rec_id_vec)[i] = net->record((*id_vec)[i], field, recFactory);
00031 }
00032
00033 return shared_ptr<SimObjectPopulation>( new SimObjectPopulation(*net, rec_id_vec) );
00034 }
00035
00036 shared_ptr<SimObjectPopulation> SimObjectPopulation::localSubPopulation()
00037 {
00038 SimObject::ID::Vector local_vec(new vector< SimObject::ID::Packed>());
00039
00040 for (int i = 0; i < (int)size() ; ++i) {
00041 if (SimObject::ID((*id_vec)[i]).node == net->mpi_rank())
00042 local_vec->push_back((*id_vec)[i]);
00043 }
00044
00045 return shared_ptr<SimObjectPopulation>( new SimObjectPopulation(*net, local_vec) );
00046 }
00047
00048 vector<size_t> * SimObjectPopulation::localIndexes()
00049 {
00050 vector<size_t> * local_idxs = new vector<size_t>;
00051 for (int i = 0; i < (int)size() ; ++i) {
00052 if (SimObject::ID((*id_vec)[i]).node == net->mpi_rank())
00053 local_idxs->push_back(i);
00054 }
00055 return local_idxs;
00056 }
00057
00058 SimObjectPopulation* SimObjectPopulation::new_subset( vector<size_t> const& subindices ) const {
00059 size_t s;
00060 vector<SimObject::ID::Packed> objIDs( subindices.size() );
00061 for( size_t i=0; i<subindices.size(); i++ ) {
00062 s = subindices[i];
00063 objIDs[i] = (*id_vec)[ s ];
00064 }
00065 return new SimObjectPopulation( *net, objIDs );
00066 }
00067
00068
00069 bool SimObjectPopulation::setFieldScale(string const & fieldname, double scale)
00070 {
00071
00072 for (int i = 0; i < (int)size() ; ++i) {
00073 SimObject::ID id = SimObject::ID((*id_vec)[i]);
00074
00075 if (SimObject::ID((*id_vec)[i]).node == net->mpi_rank()) {
00076 SimObject *obj=net->getObject(id);
00077 const Field *field=obj->findField(fieldname);
00078 obj->setScalarField(field, obj->getScalarField(field)*scale);
00079 }
00080 }
00081
00082 return true;
00083 }
00084