-
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
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 (IdxT i = 0; i < size_; ++i) | ||
|
abdourahmanbarry marked this conversation as resolved.
|
||
| { | ||
| connection_nodes_[static_cast<size_t>(i)] = other.connection_nodes_[static_cast<size_t>(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 (IdxT i = 0; i < nnz_; ++i) | ||
| { | ||
| jacobian_coo_rows_[static_cast<size_t>(i)] = other.jacobian_coo_rows_[static_cast<size_t>(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 (IdxT i = 0; i < nnz_; ++i) | ||
| { | ||
| jacobian_coo_cols_[static_cast<size_t>(i)] = other.jacobian_coo_cols_[static_cast<size_t>(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 (IdxT i = 0; i < nnz_; ++i) | ||
| { | ||
| jacobian_coo_values_[static_cast<size_t>(i)] = other.jacobian_coo_values_[static_cast<size_t>(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 (IdxT i = 0; i < 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; | ||
| } | ||
|
|
||
|
|
@@ -95,6 +227,23 @@ namespace GridKit | |
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Update the connection index for a variable. | ||
| * | ||
| * Changes 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 |
||
| /** | ||
| * @brief Given the location of value in the local vector map to global index | ||
| * | ||
|
|
@@ -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_) | ||
|
|
@@ -225,6 +375,51 @@ namespace GridKit | |
| f_int_ = internal_res; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Clear all internal and external data pointers. | ||
| * | ||
| * This disconnects the component from the data storage currently associated | ||
| * with its internal and external variables. The external pointer arrays | ||
| * themselves remain allocated so that the component can be connected to | ||
| * new data later. | ||
| * | ||
| * @return int 0 if successful. | ||
| */ | ||
| int clearPointers() | ||
| { | ||
| // Clear internal data pointers. | ||
| y_int_ = nullptr; | ||
| yp_int_ = nullptr; | ||
| f_int_ = nullptr; | ||
|
|
||
| // Clear external data pointers, but keep the pointer arrays allocated. | ||
| if (y_ext_) | ||
| { | ||
| for (IdxT i = 0; i < size_; ++i) | ||
| { | ||
| y_ext_[i] = nullptr; | ||
| } | ||
| } | ||
|
|
||
| if (yp_ext_) | ||
| { | ||
| for (IdxT i = 0; i < size_; ++i) | ||
| { | ||
| yp_ext_[i] = nullptr; | ||
| } | ||
| } | ||
|
|
||
| if (f_ext_) | ||
| { | ||
| for (IdxT i = 0; i < size_; ++i) | ||
| { | ||
| f_ext_[i] = nullptr; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
abdourahmanbarry marked this conversation as resolved.
|
||
| protected: | ||
| /** | ||
| * @brief Reset the Jacobian so it can be constructed. Helper method for \ref setJacValues(). | ||
|
|
@@ -439,6 +634,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.