Skip to content

Commit

Permalink
discretization: add a function to update the whole solver
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-iob committed May 24, 2020
1 parent 8b29c44 commit db8db53
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/discretization/stencil_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ void StencilScalarSolver::assembly(const std::vector<StencilScalar> &stencils)
}
}

/*!
* Update all the stencil solver.
*
* Only the values of the system matrix and the values of the constants can be
* updated, once the system is initialized its pattern cannot be modified.
*
* \param stencils are the stencils that will be used to update the rows
*/
void StencilScalarSolver::update(const std::vector<StencilScalar> &stencils)
{
update(getRowCount(), nullptr, stencils);
}

/*!
* Update the stencil solver.
*
Expand All @@ -322,19 +335,41 @@ void StencilScalarSolver::assembly(const std::vector<StencilScalar> &stencils)
* \param stencils are the stencils that will be used to update the rows
*/
void StencilScalarSolver::update(const std::vector<long> &rows, const std::vector<StencilScalar> &stencils)
{
update(rows.size(), rows.data(), stencils);
}

/*!
* Update the stencil solver.
*
* Only the values of the system matrix and the values of the constants can be
* updated, once the system is initialized its pattern cannot be modified.
*
* \param nRows is the number of rows that will be updated
* \param rows are the indices of the rows that will be updated,
* if a null pointer is passed, the rows that will be updated are the
* rows from 0 to (nRows - 1).
* \param stencils are the stencils that will be used to update the rows
*/
void StencilScalarSolver::update(std::size_t nRows, const long *rows, const std::vector<StencilScalar> &stencils)
{
// Assembly system
#if BITPIT_ENABLE_MPI==1
StencilSolverAssembler assembler(getCommunicator(), isPartitioned(), &stencils);
#else
StencilSolverAssembler assembler(&stencils);
#endif
SystemSolver::update(rows.size(), rows.data(), assembler);
SystemSolver::update(nRows, rows, assembler);

// Set constants
long nUpdatedRows = rows.size();
for (long n = 0; n < nUpdatedRows; ++n) {
long row = rows[n];
for (std::size_t n = 0; n < nRows; ++n) {
long row;
if (rows) {
row = rows[n];
} else {
row = n;
}

m_constants[row] = assembler.getRowConstant(n);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/discretization/stencil_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class StencilScalarSolver : public SystemSolver {
#if BITPIT_ENABLE_MPI==1
void assembly(MPI_Comm communicator, bool partitioned, const std::vector<StencilScalar> &stencils);
#endif
void update(const std::vector<StencilScalar> &stencils);
void update(const std::vector<long> &rows, const std::vector<StencilScalar> &stencils);
void update(std::size_t nRows, const long *rows, const std::vector<StencilScalar> &stencils);

void solve();

Expand Down

0 comments on commit db8db53

Please sign in to comment.