-
Notifications
You must be signed in to change notification settings - Fork 10
Initial Implementation of Subsystem Model for Partition Simulation #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
547cac8
7463300
ea84ec5
2dd8fe8
a0b7a50
82c0efc
d5d84c5
1a8ba04
c9c64f2
9692e57
9950483
3609340
5ef63d3
c60ba33
89ee325
1e99fc3
5437b89
5506d2b
288acab
1e6a67e
67eb9bc
67435a5
c1e3bd4
74ac54a
0bd364a
3b62428
261ea10
a8bf8bb
1ba215c
eb528de
6328a8a
96ac403
4ce744b
1887bf0
19a0a6f
7fa22d6
23eeacf
2e360d9
838af48
c8a6dcb
f082543
6bb5472
367e193
d87215d
7628dc5
f5c2134
9053f17
7c19edb
9f85ee1
93d0442
54af398
938a7ff
2ed1b83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,138 @@ namespace GridKit | |
|
|
||
| CircuitComponent() = default; | ||
|
|
||
| CircuitComponent(const CircuitComponent& other) | ||
| : n_extern_(other.n_extern_), | ||
| n_intern_(other.n_intern_), | ||
| extern_indices_(other.extern_indices_), | ||
| size_(other.size_), | ||
| nnz_(other.nnz_), | ||
| size_quad_(other.size_quad_), | ||
| size_opt_(other.size_opt_), | ||
| current_jac_size_(other.current_jac_size_), | ||
|
|
||
| // These pointers refer to storage supplied by a parent system. | ||
| // The copied component must be connected to its own storage later. | ||
| y_int_(nullptr), | ||
| yp_int_(nullptr), | ||
| f_int_(nullptr), | ||
|
|
||
| tag_(other.tag_), | ||
| time_(other.time_), | ||
| alpha_(other.alpha_), | ||
| max_steps_(other.max_steps_), | ||
| idc_(other.idc_), | ||
| allocated_(other.allocated_) | ||
| { | ||
| /* | ||
| * VectorT disables its normal copy constructor and copy-assignment | ||
| * operator. Use its provided copyFromExternal() operation to perform | ||
| * an independent copy of the vector data. | ||
| */ | ||
| auto copyVector = [](VectorT& destination, const VectorT& source) | ||
| { | ||
| const IdxT source_size = source.getSize(); | ||
|
|
||
| if (source_size == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| destination.resize(source_size); | ||
| destination.copyFromExternal(source); | ||
| }; | ||
|
|
||
| /* | ||
| * Deep-copy the local-to-global connection mapping. | ||
| */ | ||
| if (other.connection_nodes_) | ||
| { | ||
| connection_nodes_ = std::make_unique<IdxT[]>(static_cast<size_t>(size_)); | ||
|
|
||
| for (size_t i = 0; i < static_cast<size_t>(size_); ++i) | ||
| { | ||
| connection_nodes_[i] = other.connection_nodes_[i]; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Deep-copy the COO Jacobian row indices. | ||
| */ | ||
| if (other.jacobian_coo_rows_) | ||
| { | ||
| jacobian_coo_rows_ = std::make_unique<IdxT[]>(static_cast<size_t>(nnz_)); | ||
|
|
||
| for (size_t i = 0; i < static_cast<size_t>(nnz_); ++i) | ||
| { | ||
| jacobian_coo_rows_[i] = other.jacobian_coo_rows_[i]; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Deep-copy the COO Jacobian column indices. | ||
| */ | ||
| if (other.jacobian_coo_cols_) | ||
| { | ||
| jacobian_coo_cols_ = std::make_unique<IdxT[]>(static_cast<size_t>(nnz_)); | ||
|
|
||
| for (size_t i = 0; i < static_cast<size_t>(nnz_); ++i) | ||
| { | ||
| jacobian_coo_cols_[i] = other.jacobian_coo_cols_[i]; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Deep-copy the COO Jacobian values. | ||
| */ | ||
| if (other.jacobian_coo_values_) | ||
| { | ||
| jacobian_coo_values_ = std::make_unique<RealT[]>(static_cast<size_t>(nnz_)); | ||
|
|
||
| for (size_t i = 0; i < static_cast<size_t>(nnz_); ++i) | ||
| { | ||
| jacobian_coo_values_[i] = other.jacobian_coo_values_[i]; | ||
| } | ||
| } | ||
|
|
||
| if (size_ > 0) | ||
| { | ||
| y_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| yp_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| f_ext_ = std::make_unique<ScalarT*[]>(static_cast<size_t>(size_)); | ||
|
|
||
| for (size_t i = 0; i < static_cast<size_t>(size_); ++i) | ||
| { | ||
| y_ext_[i] = nullptr; | ||
| yp_ext_[i] = nullptr; | ||
| f_ext_[i] = nullptr; | ||
| } | ||
| } | ||
|
|
||
| // State, state derivative, residual, and absolute tolerance. | ||
| copyVector(y_, other.y_); | ||
| copyVector(yp_, other.yp_); | ||
| copyVector(f_, other.f_); | ||
| copyVector(abs_tol_, other.abs_tol_); | ||
| copyVector(g_, other.g_); | ||
| copyVector(yB_, other.yB_); | ||
| copyVector(ypB_, other.ypB_); | ||
| copyVector(fB_, other.fB_); | ||
| copyVector(gB_, other.gB_); | ||
| copyVector(param_, other.param_); | ||
| copyVector(param_up_, other.param_up_); | ||
| copyVector(param_lo_, other.param_lo_); | ||
|
abdourahmanbarry marked this conversation as resolved.
|
||
| } | ||
|
|
||
| virtual CircuitComponent<ScalarT, IdxT>* clone() const | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| virtual bool isCloneable() const | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * @note Cannot be marked final, since it is overriden to recurse in the system model. | ||
| */ | ||
|
|
@@ -51,7 +183,7 @@ namespace GridKit | |
| return this->n_intern_; | ||
| } | ||
|
|
||
| std::set<size_t> getExternIndices() | ||
| std::set<IdxT> getExternIndices() | ||
| { | ||
| return this->extern_indices_; | ||
| } | ||
|
|
@@ -69,7 +201,7 @@ namespace GridKit | |
| int setInternalConnectionNodes(size_t local_index, IdxT global_index) | ||
| { | ||
| assert(!extern_indices_.contains(static_cast<IdxT>(local_index))); | ||
| connection_nodes_[local_index] = global_index; | ||
| setConnectionNodes(local_index, global_index); | ||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -88,10 +220,27 @@ namespace GridKit | |
| int setExternalConnectionNodes(size_t local_index, ExternalConnection<ScalarT, IdxT> connection) | ||
| { | ||
| assert(extern_indices_.contains(local_index)); | ||
| y_ext_[local_index] = connection.y_; | ||
| yp_ext_[local_index] = connection.yp_; | ||
| f_ext_[local_index] = connection.f_; | ||
| connection_nodes_[local_index] = connection.idx_; | ||
| y_ext_[local_index] = connection.y_; | ||
| yp_ext_[local_index] = connection.yp_; | ||
| f_ext_[local_index] = connection.f_; | ||
| setConnectionNodes(local_index, connection.idx_); | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Update the connection index for a variable. | ||
| * | ||
| * Sets only the connection index without modifying the variable's | ||
| * internal/external classification or its associated data pointers. | ||
| * | ||
| * @param local_index Index of the local variable. | ||
| * @param connection_index New connection index for the variable. | ||
| * | ||
| * @return int 0 if successful. | ||
| */ | ||
| int setConnectionNodes(size_t local_index, IdxT connection_index) | ||
| { | ||
| connection_nodes_[local_index] = connection_index; | ||
| return 0; | ||
| } | ||
|
|
||
|
Comment on lines
+230
to
+246
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this function need to exist in addition to Also if it's entirely necessary, you can just remove the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. connection_nodes_ describes the topology of the network, which is how component variable are connected in the network. The external data pointers describe where the current data for that variable is stored. They are related concepts, but they are not the same thing and do not necessarily have to be coupled or updated together at all times. We already do this in some part of the code. The internal variables connection indices are established independently of their internal data pointers. The Subsystem follows the same pattern for external variables. We first remap the connection indices with the appropriate subsystem local indexing, and later set the corresponding data pointers. I think it is useful to have an operation that updates only connection_nodes. Any changes to the connection nodes should be followed by setting the appropriate data pointers, which we are doing consistently in the SubsystemModel implementation. |
||
|
|
@@ -132,9 +281,10 @@ namespace GridKit | |
| jacobian_coo_cols_ = std::make_unique<IdxT[]>(static_cast<size_t>(nnz_)); | ||
| jacobian_coo_values_ = std::make_unique<RealT[]>(static_cast<size_t>(nnz_)); | ||
|
|
||
| y_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| yp_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| f_ext_ = std::make_unique<ScalarT*[]>(static_cast<size_t>(size_)); | ||
| y_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| yp_ext_ = std::make_unique<const ScalarT*[]>(static_cast<size_t>(size_)); | ||
| f_ext_ = std::make_unique<ScalarT*[]>(static_cast<size_t>(size_)); | ||
|
|
||
| connection_nodes_ = std::make_unique<IdxT[]>(static_cast<size_t>(size_)); | ||
|
|
||
| if (!allocated_) | ||
|
|
@@ -439,6 +589,16 @@ namespace GridKit | |
| return idc_; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Check whether the component has already been allocated. | ||
| * | ||
| * @return true if allocate() has previously completed, false otherwise. | ||
| */ | ||
| bool isAllocated() const | ||
| { | ||
| return allocated_; | ||
| } | ||
|
|
||
|
abdourahmanbarry marked this conversation as resolved.
|
||
| protected: | ||
| /** | ||
| * @brief Allocate state and residual storage owned by this component. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.