forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add residual and jacobain trainers and transfer options
update variable names fix issue with parallel implementation need to close jacobian for nonlinear update clears for other containers remove duplicate snapshot change clone to collect and add error checking update snapshot method update method names add option to variable mapping base save before refactor Fix snapshot container system. (idaholab#27101)
- Loading branch information
1 parent
f5ce2c7
commit ec5882c
Showing
48 changed files
with
5,887 additions
and
30 deletions.
There are no files selected for viewing
Submodule wasp
updated
from f16be3 to 28fe0d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule large_media
updated
72 files
Submodule libmesh
updated
1086 files
36 changes: 36 additions & 0 deletions
36
modules/stochastic_tools/include/reporters/JacobianContainer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "SnapshotContainerBase.h" | ||
#include "libmesh/id_types.h" | ||
#include "libmesh/petsc_vector.h" | ||
#include "libmesh/vectormap.h" | ||
|
||
/** | ||
* This class is responsible for collecting jacobian row concatenated vectors in one place. The | ||
* vectors are kept distributed with respect to the communicator of the application. | ||
* The whole jacobian row concatenated vector is stored. | ||
* The saving frequency can be defined using the `execute_on` parameter. | ||
*/ | ||
class JacobianContainer : public SnapshotContainerBase | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
JacobianContainer(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual std::unique_ptr<NumericVector<Number>> collectSnapshot() override; | ||
|
||
std::vector<std::pair<dof_id_type, dof_id_type>> & _sparse_ind; | ||
|
||
NonlinearSystem & _nl_sys; | ||
const TagID _tag_id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modules/stochastic_tools/include/reporters/ResidualContainer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "MooseTypes.h" | ||
#include "NonlinearSystemBase.h" | ||
#include "SnapshotContainerBase.h" | ||
#include "SystemBase.h" | ||
#include "libmesh/petsc_vector.h" | ||
|
||
/** | ||
* This class is responsible for collecting residual vectors in one place. The | ||
* vectors are kept distributed with respect to the communicator of the application. | ||
* The whole residual vector is stored. | ||
* The saving frequency can be defined using the `execute_on` parameter. | ||
*/ | ||
class ResidualContainer : public SnapshotContainerBase | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
ResidualContainer(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual std::unique_ptr<NumericVector<Number>> collectSnapshot() override; | ||
|
||
const NonlinearSystem & _nl_sys; | ||
const TagID _tag_id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
modules/stochastic_tools/include/transfers/SerializedSnapshotTransfer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
// MOOSE includes | ||
#include "ParallelSolutionStorage.h" | ||
#include "StochasticToolsTransfer.h" | ||
#include "SnapshotContainerBase.h" | ||
#include "UserObjectInterface.h" | ||
|
||
// Forward declarations | ||
class ParallelSolutionStorage; | ||
|
||
/** | ||
* This class is responsible for serializing solutions coming from subapps on | ||
* specific processors. It is designed to serve as an interface between | ||
* SolutionContainer and ParallelSolutionStorage objects. | ||
*/ | ||
class SerializedSnapshotTransfer : public StochasticToolsTransfer | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
SerializedSnapshotTransfer(const InputParameters & parameters); | ||
|
||
virtual void initialSetup() override; | ||
virtual void execute() override; | ||
|
||
///@{ | ||
/** | ||
* Methods used when running in batch mode (see SamplerFullSolveMultiApp) | ||
*/ | ||
void initializeFromMultiapp() override {} | ||
void executeFromMultiapp() override; | ||
void finalizeFromMultiapp() override {} | ||
|
||
void initializeToMultiapp() override {} | ||
void executeToMultiapp() override {} | ||
void finalizeToMultiapp() override {} | ||
///@} | ||
|
||
protected: | ||
/// The storage on the main application where the serialized solutions should be | ||
/// transferred | ||
ParallelSolutionStorage * _parallel_storage; | ||
|
||
/// Link to the storage spaces on the subapplications (will only hold one in batch mode) | ||
std::vector<SnapshotContainerBase *> _solution_container; | ||
/// Link to the storage spaces on the subapplications (will only hold one in batch mode) | ||
std::vector<SnapshotContainerBase *> _residual_container; | ||
/// Link to the storage spaces on the subapplications (will only hold one in batch mode) | ||
std::vector<SnapshotContainerBase *> _jacobian_container; | ||
|
||
private: | ||
/// Serialize on the root processor of the subapplication and transfer the result to the main application | ||
void transferToSubAppRoot(FEProblemBase & app_problem, | ||
SnapshotContainerBase & snap_container, | ||
const dof_id_type global_i, | ||
const std::string snapshot_type); | ||
|
||
/** | ||
* Serialize on methodically determined rank of the subapp and transfer to the main application. | ||
* Example: Let's say we have 5 samples and 3 processors on a sub-application. | ||
* In this case, we will serialize the first two on rank 1, the second two on rank | ||
* 2 and the last one on rank 3. | ||
*/ | ||
void transferInParallel(FEProblemBase & app_problem, | ||
SnapshotContainerBase & snap_container, | ||
const dof_id_type global_i, | ||
const std::string snapshot_type); | ||
|
||
/** | ||
* Initializes the solution container if the multiapp is run in normal mode. We need this because | ||
* in normal mode we don't have a function for initialization besides `initialSetup()`, which | ||
* is execute every time regardless of the multiapp settings. | ||
*/ | ||
void initializeInNormalMode(); | ||
|
||
/// This routine queries the solution container addresses from the subapps. We need to redo this | ||
/// every time initialSetup() (batch-reset) is called on the subapp because the address | ||
/// of SolutionContainer changes. Considering that the transfer doesn't know the multiapp | ||
/// setting, we use the same approach for batch-restore as well, which might be a little | ||
/// wasteful if the execution of the subapps is very fast (usually not the case). | ||
void initializeInBatchMode(); | ||
|
||
/// Return the system which contains the given variable. It can either be a flavor of | ||
/// a nonlinear system or the auxiliary system. | ||
/// @param vname The name of the variable whose system is queried | ||
SystemBase & getSystem(FEProblemBase & app_problem, const VariableName & vname); | ||
|
||
/// User-selected switch that determines if we want to serialize on the root of the subapp | ||
/// only or distribute the solutions between all the ranks of the subapp. | ||
const bool _serialize_on_root; | ||
}; |
165 changes: 165 additions & 0 deletions
165
modules/stochastic_tools/include/userobjects/InverseRB.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
///* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "DEIMRBMapping.h" | ||
#include "GeneralUserObject.h" | ||
#include "MappingInterface.h" | ||
#include "NonlinearSystemBase.h" | ||
#include "SystemBase.h" | ||
#include "libmesh/elem.h" | ||
#include "libmesh/elem_range.h" | ||
#include "libmesh/id_types.h" | ||
#include <memory> | ||
|
||
/** | ||
* InverseRB is a user object that performs inverse reduced basis mapping. | ||
*/ | ||
class InverseRB : public GeneralUserObject, public MappingInterface | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
/** | ||
* Constructor for InverseRB. | ||
* @param parameters Input parameters | ||
*/ | ||
InverseRB(const InputParameters & parameters); | ||
|
||
virtual void initialize() override; | ||
|
||
virtual void execute() override; | ||
|
||
virtual void finalize() override; | ||
|
||
virtual void initialSetup() override; | ||
|
||
// only needed for ElementUserObjects and NodalUseroObjects | ||
virtual void threadJoin(const UserObject & /*y*/) override{}; | ||
|
||
protected: | ||
/// Link to the mapping object which provides the inverse mapping function | ||
DEIMRBMapping * _mapping; | ||
|
||
std::vector<dof_id_type> _residual_inds; | ||
|
||
std::vector<std::pair<dof_id_type, dof_id_type>> _jacobian_matrix_inds; | ||
|
||
const DofMap & _dof_map; | ||
|
||
const dof_id_type _max_iter; | ||
|
||
const Real _tolerance; | ||
|
||
const Real _relax_factor; | ||
|
||
private: | ||
/** | ||
* Finds the reduced element range for the given DOFs. | ||
* @param dofs Vector of DOF indices | ||
* @return Vector of pointers to the reduced elements | ||
*/ | ||
std::vector<const Elem *> findReducedElemRange(const std::vector<dof_id_type> & dofs); | ||
|
||
/** | ||
* Finds the reduced node range for the given DOFs. | ||
* @param dofs Vector of DOF indices | ||
* @return Vector of pointers to the reduced nodes | ||
*/ | ||
std::vector<const Node *> findReducedNodeRange(const std::vector<dof_id_type> & dofs); | ||
|
||
/** | ||
* Creates a range object from a vector of items. | ||
* @tparam RangeType Type of the range object | ||
* @tparam ItemType Type of the items in the vector | ||
* @tparam IteratorType Type of the iterator for the range object | ||
* @param items Vector of pointers to the items | ||
* @return Unique pointer to the created range object | ||
*/ | ||
template <typename RangeType, typename ItemType, typename IteratorType> | ||
std::unique_ptr<RangeType> createRangeFromVector(const std::vector<const ItemType *> & items); | ||
|
||
/** | ||
* Retrieves the reduced Jacobian values from the sparse matrix. | ||
* @param jac Sparse Jacobian matrix | ||
* @return Vector of reduced Jacobian values | ||
*/ | ||
std::vector<Real> getReducedJacValues(const SparseMatrix<Number> & jac); | ||
|
||
/** | ||
* Retrieves the reduced residual values from the numeric vector. | ||
* @param res Numeric residual vector | ||
* @return Reduced residual values | ||
*/ | ||
std::vector<Real> getReducedResValues(const NumericVector<Number> & res); | ||
|
||
/** | ||
* Computes the reduced Jacobian matrix. | ||
* @return Reduced Jacobian | ||
*/ | ||
DenseMatrix<Real> computeReducedJacobian(); | ||
|
||
/** | ||
* Computes the reduced residual vector. | ||
* @return Reduced residual | ||
*/ | ||
DenseVector<Real> computeReducedResidual(); | ||
|
||
/** | ||
* Updates the solution vector with the reduced solution. | ||
* @param reduced_sol Reduced solution vector | ||
*/ | ||
void updateSolution(const DenseVector<Real> & reduced_sol); | ||
|
||
/** | ||
* Computes the residual norm. | ||
* @return Residual norm value | ||
*/ | ||
Real computeResidual(); | ||
|
||
/// Vector of reduced Jacobian elements | ||
std::vector<const Elem *> _red_jac_elem; | ||
|
||
/// Vector of reduced residual elements | ||
std::vector<const Elem *> _red_res_elem; | ||
|
||
/// Vector of reduced Jacobian nodes | ||
std::vector<const Node *> _red_jac_node; | ||
|
||
/// Vector of reduced residual nodes | ||
std::vector<const Node *> _red_res_node; | ||
|
||
/// Local range of reduced Jacobian elements | ||
std::unique_ptr<ConstElemRange> _red_jac_elem_local_range; | ||
|
||
/// Local range of reduced residual elements | ||
std::unique_ptr<ConstElemRange> _red_res_elem_local_range; | ||
|
||
/// Local range of reduced Jacobian nodes | ||
std::unique_ptr<ConstNodeRange> _red_jac_node_local_range; | ||
|
||
/// Local range of reduced residual nodes | ||
std::unique_ptr<ConstNodeRange> _red_res_node_local_range; | ||
|
||
/// Nonlinear system | ||
NonlinearSystemBase & _nl_sys; | ||
|
||
/// Jacobian matrix | ||
SparseMatrix<Number> * _jac_matrix; | ||
|
||
/// Residual vector | ||
NumericVector<Number> * _residual; | ||
|
||
/// Current solution | ||
const NumericVector<Number> * _curr_sol; | ||
|
||
/// Linear solver | ||
LinearSolver<Number> * _solver; | ||
}; |
Oops, something went wrong.