-
Notifications
You must be signed in to change notification settings - Fork 7
Add Power Electronics sparsity pattern computation into allocate #307
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?
Conversation
|
I also wanted to add an additional comment on the removal of the short-circuiting condition in I found out yesterday that IDA sets the |
pelesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress. Some design tweaks are needed but we are almost there..
| std::vector<std::vector<ComponentContribution>> reverse_map(size_); | ||
| std::vector<CsrSparsity> component_sparsities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid using STL containers here. What we need to do is to
- populate row pointers and column indices in the CSR Jacobian matrix
- have components store mapping from their Jacobian elements to the index of column indices array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot really remove the STL container for reverse_map... the size of the second level arrays are unknown ahead of time and need to be dynamically grown. I can remove the vector for component_sparsities, though
| // Helper struct for identifying a particular component's local system variable | ||
| struct ComponentContribution | ||
| { | ||
| // The index of the component in `components_`. | ||
| size_t comp_idx_; | ||
| // The local system variable index | ||
| size_t local_row_idx_; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is a good idea. Ideally, one should loop through components and components would read/write at locations determined by the connectivity information. The system composer should remain agnostic of specific details of the components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well a component cannot write all of its info at once, so I must have some way of differentiating the different parts of info that a component needs to write at once.
Previously, axpy would do no work if a == 0, but this can change sparsity patterns. Typically, a > 0 during simulations anyway, so this only affects when axpy's are done e.g. before simulation, when memory is unset.
Also added a unit test which compares sparsity pattern generated by DependencyTracking::Variable and new sparsity pattern on microgrid problem.
aab85f1 to
759f22f
Compare
|
rebase w.r.t. develop |
Due to the way that assignment operators are currently implemented in CsrMatrix, there is a memory issue.
|
I changed the sparsity to be calculated into @nkoukpaizan maybe it's worth fixing? I can do some wonky stuff to try and avoid it but it seems to me like maybe it's better to just fix the bug? |
Wouldn't it work if we stored |
That's the wonky stuff I meant. Is |
I don't see are need to use assignment operator either (and it might be a good idea to delete it tbh). The implementation should go something like this:
This is what is needed to address #301. |
But as far as I can tell, there is no way to change the size of the matrix after construction. And the size of the system is not known at construction time for |
You could also have class SystemSolverPowerElectronics
{
public:
// some code
private:
CsrMatrix jacobian_;
};In that case Jacobian matrix would be instantiated with a default constructor and you would allocate it and populate its data arrays. That wouldn't change much in the approach. |
You implemented |
|
I copied the implementation from ReSolve, I'm not really familiar with how it works. It kind of seemed to me like there may have been a good reason why there wasn't a |
|
Well, as far as I can tell |
Also removed vector for global_col_indices, instead allocating once with an upper bound of the combined nnz of the components. This shouldn't be *too* much of an over-estimation.
|
Okay, I went ahead an imposed the correct system vector ordering. The Now that the ordering is required to be nice, I went ahead and updated the jacobian sparsity computations to take advantage of it - first the internal rows are done component-by-component, then the heavier reverse-mapping machinery is invoked only for the external rows. I also realized that I could use the sum of the component Jacobian |
|
@pelesh I implemented what we discussed at the SciDAC meeting, and am not depending on the components having their jacobians in CSR form anymore (just using COO). The two outstanding pieces of feedback, though, I'm waiting for your feedback on. Maybe we can talk about them in a code review? |
Description
Adds sparsity pattern computation into
PowerElectronicsModel::allocate().Closes #301
Checklist
Put an
xin the boxes that apply. You can also fill these out after creatingthe PR. If you're unsure about any of them, don't hesitate to ask. We're here
to help! This is simply a reminder of what we are going to look for before
merging your code.
-Wall -Wpedantic -Wconversion -Wextra.Further comments
I added a couple of helper structs, but these are only there for cache locality and readability purposes. They are local to the function itself. Additionally, I made use of
std::vectoras a dynamically growing container, but all final products end up as simple pointers.