59 template <
class Ins >
120 for (
int d = 0; d < D; ++d )
122 this->
lower_left_[ d ] = std::numeric_limits< double >::infinity();
123 max_point[ d ] = -std::numeric_limits< double >::infinity();
127 this->node_collection_->end(),
131 const auto node = kernel().node_manager.get_mpi_local_node_or_device_head( b.node_id );
132 return node->is_proxy() ? a : a + 1;
139 if ( std::holds_alternative< std::vector< std::vector< double > > >( positions ) )
145 const auto pos = std::get< std::vector< std::vector< double > > >( positions );
146 for (
auto it = pos.begin(); it != pos.end(); ++it, ++nc_it )
152 if ( not node->is_proxy() )
158 for (
int d = 0; d < D; ++d )
164 if ( point[ d ] > max_point[ d ] )
166 max_point[ d ] = point[ d ];
172 else if ( std::holds_alternative< std::shared_ptr< Parameter > >( positions ) )
189 if ( not node->is_proxy() )
195 for (
int d = 0; d < D; ++d )
201 if ( point[ d ] > max_point[ d ] )
203 max_point[ d ] = point[ d ];
211 throw KernelException(
"'positions' must be an array or a DimensionParameter." );
223 auto upper_right_limit = center + this->
extent_ / 2;
224 for (
int d = 0; d < D; ++d )
226 if ( lower_left_point[ d ] < this->
lower_left_[ d ] or max_point[ d ] > upper_right_limit[ d ] )
228 throw BadProperty(
"Node position outside of layer" );
236 throw KernelException(
"If only one node is created, 'extent' must be specified." );
239 const auto positional_extent = max_point - this->
lower_left_;
240 const auto center = ( max_point + this->lower_left_ ) / 2;
241 for (
int d = 0; d < D; ++d )
244 this->
extent_[ d ] = std::ceil( positional_extent[ d ] );
248 this->lower_left_ = center - this->
extent_ / 2;
258 std::vector< std::vector< double > > points;
265 points.emplace_back( pos.get_vector() );
278 const auto nc_end = nc->
end();
279 if ( nc_it < nc_end )
284 size_t pos_idx = ( *nc_it ).nc_index / n_procs;
285 const size_t step = nc_it.get_step_size() / n_procs;
287 for ( ; nc_it < nc->
end(); pos_idx += step, ++nc_it )
289 points.emplace_back(
positions_.at( pos_idx ).get_vector() );
305template <
class Ins >
310 std::vector< double > local_node_id_pos;
318 node_collection->has_proxies() ? node_collection->rank_local_begin() : node_collection->begin();
327 local_node_id_pos.push_back( ( *nc_it ).node_id );
330 for (
int j = 0; j < D; ++j )
332 local_node_id_pos.push_back( pos[ j ] );
337 std::vector< double > global_node_id_pos;
338 std::vector< int > displacements;
345 pos_ptr =
reinterpret_cast< NodePositionData*
>( &global_node_id_pos[ 0 ] );
346 pos_end = pos_ptr + global_node_id_pos.size() / ( D + 1 );
349 std::sort( pos_ptr, pos_end );
350 pos_end = std::unique( pos_ptr, pos_end );
353 for ( ; pos_ptr < pos_end; pos_ptr++ )
372 return a.second < b.second;
403 return lid / num_procs;
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
NodeCollectionPTR node_collection_
The NodeCollection to which the layer belongs.
Definition layer.h:182
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
Position-generating Parameter class.
Definition parameter.h:1155
Class to be used when communicating positions across MPI processes.
Definition free_layer.h:83
size_t get_node_id() const
Definition free_layer.h:86
Position< D > get_position() const
Definition free_layer.h:91
bool operator<(const NodePositionData &other) const
Definition free_layer.h:96
bool operator==(const NodePositionData &other) const
Definition free_layer.h:101
double pos_[D]
Definition free_layer.h:108
double node_id_
Definition free_layer.h:107
Layer with free positioning of neurons, positions specified by user.
Definition free_layer.h:47
void insert_global_positions_ntree_(Ntree< D, size_t > &tree, NodeCollectionPTR node_collection) override
Insert global position info into ntree.
Definition free_layer.h:361
size_t lid_to_position_id_(size_t lid) const
Calculate the index in the position vector on this MPI process based on the local ID.
Definition free_layer.h:389
void get_status(Dictionary &, NodeCollection const *const) const override
Export properties of the layer by setting entries in the status dictionary, respects slicing of given...
Definition free_layer.h:254
void insert_global_positions_vector_(std::vector< std::pair< Position< D >, size_t > > &vec, NodeCollectionPTR node_collection) override
Insert global position info into vector.
Definition free_layer.h:377
std::vector< Position< D > > positions_
Vector of positions.
Definition free_layer.h:75
Position< D > get_position(size_t sind) const override
Get position of node.
Definition free_layer.h:299
void communicate_positions_(Ins iter, NodeCollectionPTR node_collection)
Communicate positions across MPI processes.
Definition free_layer.h:307
void set_status(const Dictionary &) override
Change properties of the layer according to the entries in the dictionary.
Definition free_layer.h:114
size_t num_local_nodes_
Definition free_layer.h:77
Base class for all Kernel exceptions.
Definition exceptions.h:65
Position< D > extent_
size of layer
Definition layer.h:440
Layer()
Creates an empty layer.
Definition layer.h:590
void set_status(const Dictionary &) override
Change properties of the layer according to the entries in the dictionary.
Definition layer_impl.h:80
void get_status(Dictionary &, NodeCollection const *const) const override
Retrieve status, slice according to node collection if given.
Definition layer_impl.h:93
Position< D > lower_left_
lower left corner (minimum coordinates) of layer
Definition layer.h:439
size_t get_num_processes() const
Return the number of processes used during simulation.
Definition mpi_manager.h:492
void communicate(std::vector< size_t > &send_buffer, std::vector< size_t > &recv_buffer)
Definition mpi_manager.cpp:1105
Superclass for NodeCollections.
Definition node_collection.h:565
virtual const_iterator rank_local_begin(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the beginning of the NodeCollection.
virtual const_iterator end(NodeCollectionPTR=NodeCollectionPTR(nullptr)) const =0
Method to get an iterator representing the end of the NodeCollection.
nc_const_iterator const_iterator
Definition node_collection.h:569
Represent single node entry in node collection.
Definition node_collection.h:92
Node * get_mpi_local_node_or_device_head(size_t)
Return pointer of Node on the thread we are on.
Definition node_manager.cpp:465
A Ntree object represents a subtree or leaf in a Ntree structure.
Definition ntree.h:55
NodeManager node_manager
Definition kernel_manager.h:245
MPIManager mpi_manager
Definition kernel_manager.h:233
const std::string positions("positions")
const std::string extent("extent")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
RngPtr get_rank_synced_rng()
Definition kernel_manager.h:286
BaseRandomGenerator * RngPtr
Definition random_generators.h:50
static bool node_id_less(const std::pair< Position< D >, size_t > &a, const std::pair< Position< D >, size_t > &b)
Definition free_layer.h:370
KernelManager & kernel()
Definition kernel_manager.h:311
std::shared_ptr< NodeCollection > NodeCollectionPTR
Definition node_collection.h:50
std::shared_ptr< Parameter > ParameterPTR
Definition parameter.h:40
std::vector< std::vector< double > > get_position(NodeCollectionPTR layer_nc)
Definition spatial.cpp:83