NEST main@caf0ae8
 
Loading...
Searching...
No Matches
model_manager_impl.h
Go to the documentation of this file.
1/*
2 * model_manager_impl.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef MODEL_MANAGER_IMPL_H
24#define MODEL_MANAGER_IMPL_H
25
26#include "model_manager.h"
27
28// Includes from libnestutil:
29#include "compose.hpp"
30
31// Includes from nestkernel:
32#include "connection_label.h"
33#include "exceptions.h"
34#include "kernel_manager.h"
35#include "nest.h"
36#include "target_identifier.h"
37
38
39namespace nest
40{
41
42template < class ModelT >
43size_t
44ModelManager::register_node_model( const std::string& name, std::string deprecation_info )
45{
46 if ( modeldict_.known( name ) )
47 {
48 const std::string msg =
49 String::compose( "A model called '%1' already exists. Please choose a different name!", name );
50 throw NamingConflict( msg );
51 }
52
53 Model* model = new GenericModel< ModelT >( name, deprecation_info );
54 return register_node_model_( model );
55}
56
57template < template < typename targetidentifierT > class ConnectionT >
58void
60{
61 // Required to check which variants to create
62 ConnectorModel const* const dummy_model =
64
65 register_specific_connection_model_< ConnectionT< TargetIdentifierPtrRport > >( name );
67 {
68 register_specific_connection_model_< ConnectionT< TargetIdentifierIndex > >( name + "_hpc" );
69 }
71 {
72 register_specific_connection_model_< ConnectionLabel< ConnectionT< TargetIdentifierPtrRport > > >( name + "_lbl" );
73 }
74
75 delete dummy_model;
76}
77
78template < typename CompleteConnectionT >
79void
81{
83
84 if ( synapsedict_.known( name ) )
85 {
86 std::string msg =
87 String::compose( "A synapse type called '%1' already exists.\nPlease choose a different name!", name );
88 throw NamingConflict( msg );
89 }
90
91 const auto new_syn_id = get_num_connection_models();
92 if ( new_syn_id >= invalid_synindex )
93 {
94 const std::string msg = String::compose(
95 "CopyModel cannot generate another synapse. Maximal synapse model count of %1 exceeded.", MAX_SYN_ID );
96 LOG( VerbosityLevel::ERROR, "ModelManager::copy_connection_model_", msg );
97 throw KernelException( "Synapse model count exceeded" );
98 }
99
100 synapsedict_[ name ] = static_cast< long >( new_syn_id );
101
102#pragma omp parallel
103 {
105 conn_model->set_syn_id( new_syn_id );
107 {
108 conn_model->get_secondary_event()->add_syn_id( new_syn_id );
109 }
110 connection_models_.at( kernel().vp_manager.get_thread_id() ).push_back( conn_model );
112 } // end of parallel section
113}
114
115inline Node*
116ModelManager::get_proxy_node( size_t tid, size_t node_id )
117{
118 const int model_id = kernel().modelrange_manager.get_model_id( node_id );
119 Node* proxy = proxy_nodes_[ tid ].at( model_id );
120 proxy->set_node_id_( node_id );
121 proxy->set_vp( kernel().vp_manager.node_id_to_vp( node_id ) );
122 return proxy;
123}
124
125} // namespace nest
126
127#endif /* #ifndef MODEL_MANAGER_IMPL_H */
bool known(const std::string &key) const
Check whether there exists a value with specified key in the dictionary.
Definition dictionary.h:677
void resize_connections()
Definition connection_manager.cpp:1714
Definition connector_model.h:69
bool has_property(const ConnectionModelProperties &property) const
Definition connector_model.h:132
virtual void set_syn_id(synindex syn_id)=0
virtual std::unique_ptr< SecondaryEvent > get_secondary_event()=0
Definition connector_model.h:152
Generic Model template.
Definition genericmodel.h:46
Base class for all Kernel exceptions.
Definition exceptions.h:65
std::vector< std::vector< ConnectorModel * > > connection_models_
The list of connection models.
Definition model_manager.h:265
size_t get_num_connection_models() const
Definition model_manager.cpp:99
void register_connection_model(const std::string &name)
Register a synape model with a custom Connector model and without any common properties.
Definition model_manager_impl.h:59
std::vector< std::vector< Node * > > proxy_nodes_
Placeholders for remote nodes, one per thread.
Definition model_manager.h:275
void register_specific_connection_model_(const std::string &name)
Definition model_manager_impl.h:80
Dictionary synapsedict_
Dictionary of all synapse models.
Definition model_manager.h:268
size_t register_node_model_(Model *model)
Definition model_manager.cpp:162
Dictionary modeldict_
Dictionary of all node models.
Definition model_manager.h:267
size_t register_node_model(const std::string &name, std::string deprecation_info=std::string())
Register a node-model prototype.
Definition model_manager_impl.h:44
Node * get_proxy_node(size_t tid, size_t node_id)
Definition model_manager_impl.h:116
size_t get_model_id(size_t node_id) const
Get the ID of the model to which this node ID is assigned.
Definition modelrange_manager.cpp:81
Base class for all Models.
Definition model.h:53
Throw if an existing name is attempted to be redefined.
Definition exceptions.h:1099
Base class for all NEST network objects.
Definition node.h:99
void set_vp(size_t)
Store the number of the virtual process to which the node is assigned.
Definition node.h:1244
void set_node_id_(size_t)
Set global node id.
Definition node.h:1207
void assert_single_threaded() const
Fails if NEST is in thread-parallel section.
Definition vp_manager.h:192
ConnectionManager connection_manager
Definition kernel_manager.h:239
ModelRangeManager modelrange_manager
Definition kernel_manager.h:238
VPManager vp_manager
Definition kernel_manager.h:234
#define LOG(s, fctn, msg)
Definition logging.h:29
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
constexpr synindex invalid_synindex
Definition nest_types.h:116
constexpr uint64_t MAX_SYN_ID
Definition nest_types.h:96
KernelManager & kernel()
Definition kernel_manager.h:311