forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create infrastructure in FEProblem and Compute*JacobianThread as well…
… as NonlocalIntegratedBC (issue idaholab#7980).
- Loading branch information
Alex Lindsay
committed
Nov 3, 2016
1 parent
fe584dd
commit 15bc94a
Showing
15 changed files
with
851 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,71 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#ifndef NONLOCALINTEGRATEDBC_H | ||
#define NONLOCALINTEGRATEDBC_H | ||
|
||
#include "IntegratedBC.h" | ||
|
||
class NonlocalIntegratedBC; | ||
|
||
template<> | ||
InputParameters validParams<NonlocalIntegratedBC>(); | ||
|
||
/** | ||
* NonlocalIntegratedBC is used for solving integral terms in integro-differential equations. | ||
* Integro-differential equations includes spatial integral terms over variables in the domain. | ||
* In this case the jacobian calculation is not restricted to local dofs of an element, it requires | ||
* additional contributions from all the dofs in the domain. NonlocalIntegratedBC adds capability to consider | ||
* nonlocal jacobians in addition to the local jacobians. | ||
*/ | ||
class NonlocalIntegratedBC : public IntegratedBC | ||
{ | ||
public: | ||
NonlocalIntegratedBC(const InputParameters & parameters); | ||
|
||
/** | ||
* computeJacobian and computeQpOffDiagJacobian methods are almost same | ||
* as IntegratedBC except for few additional optimization options regarding the integral terms. | ||
* Looping order of _i & _j are reversed for providing opimization options and | ||
* additional getUserObjectJacobian method is provided as an option to obtain | ||
* jocobians of the integral term from userobject once per dof | ||
*/ | ||
virtual void computeJacobian(); | ||
virtual void computeOffDiagJacobian(unsigned int jvar); | ||
|
||
/** | ||
* computeNonlocalJacobian and computeNonlocalOffDiagJacobian methods are | ||
* introduced for providing the jacobian contribution corresponding to nolocal dofs. | ||
* Nonlocal jacobian block is sized with respect to the all the dofs of jacobian variable. | ||
* Looping order of _i & _k are reversed for opimization purpose and | ||
* additional globalDoFEnabled method is provided as an option to execute nonlocal | ||
* jocobian calculations only for nonlocal dofs that has nonzero jacobian contribution. | ||
*/ | ||
virtual void computeNonlocalJacobian(); | ||
virtual void computeNonlocalOffDiagJacobian(unsigned int jvar); | ||
|
||
protected: | ||
/// Compute this IntegratedBC's contribution to the Jacobian corresponding to nolocal dof at the current quadrature point | ||
virtual Real computeQpNonlocalJacobian(dof_id_type /*dof_index*/) { return 0; } | ||
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int /*jvar*/, dof_id_type /*dof_index*/) { return 0; } | ||
|
||
/// Optimization option for getting jocobinas from userobject once per dof | ||
virtual void getUserObjectJacobian(unsigned int /*jvar*/, dof_id_type /*dof_index*/) {} | ||
/// optimization option for executing nonlocal jacobian calculation only for nonzero elements | ||
virtual bool globalDoFEnabled(MooseVariable & /*var*/, dof_id_type /*dof_index*/) { return true; } | ||
|
||
unsigned int _k; | ||
}; | ||
|
||
#endif /* NONLOCALINTEGRATEDBC_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
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
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
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,151 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#include "NonlocalIntegratedBC.h" | ||
#include "Assembly.h" | ||
#include "MooseVariable.h" | ||
#include "Problem.h" | ||
#include "SubProblem.h" | ||
#include "SystemBase.h" | ||
#include "MooseMesh.h" | ||
|
||
// libmesh includes | ||
#include "libmesh/threads.h" | ||
#include "libmesh/quadrature.h" | ||
|
||
template<> | ||
InputParameters validParams<NonlocalIntegratedBC>() | ||
{ | ||
InputParameters params = validParams<IntegratedBC>(); | ||
return params; | ||
} | ||
|
||
NonlocalIntegratedBC::NonlocalIntegratedBC(const InputParameters & parameters) : | ||
IntegratedBC(parameters) | ||
{ | ||
_mesh.errorIfDistributedMesh("NonlocalIntegratedBC"); | ||
mooseWarning("NonlocalIntegratedBC is a computationally expensive experimental capability used only for integral terms."); | ||
} | ||
|
||
void | ||
NonlocalIntegratedBC::computeJacobian() | ||
{ | ||
DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), _var.number()); | ||
_local_ke.resize(ke.m(), ke.n()); | ||
_local_ke.zero(); | ||
|
||
for (_j = 0; _j < _phi.size(); _j++) // looping order for _i & _j are reversed for performance improvement | ||
{ | ||
getUserObjectJacobian(_var.number(), _var.dofIndices()[_j]); | ||
for (_i = 0; _i < _test.size(); _i++) | ||
for (_qp = 0; _qp < _qrule->n_points(); _qp++) | ||
_local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpJacobian(); | ||
} | ||
|
||
ke += _local_ke; | ||
|
||
if (_has_diag_save_in) | ||
{ | ||
unsigned int rows = ke.m(); | ||
DenseVector<Number> diag(rows); | ||
for (unsigned int i=0; i<rows; i++) | ||
diag(i) = _local_ke(i,i); | ||
|
||
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); | ||
for (const auto & var : _diag_save_in) | ||
var->sys().solution().add_vector(diag, var->dofIndices()); | ||
} | ||
} | ||
|
||
void | ||
NonlocalIntegratedBC::computeOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (jvar == _var.number()) | ||
computeJacobian(); | ||
else | ||
{ | ||
MooseVariable & jv = _sys.getVariable(_tid, jvar); | ||
DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar); | ||
|
||
for (_j = 0; _j < _phi.size(); _j++) // looping order for _i & _j are reversed for performance improvement | ||
{ | ||
getUserObjectJacobian(jvar, jv.dofIndices()[_j]); | ||
for (_i = 0; _i < _test.size(); _i++) | ||
for (_qp = 0; _qp < _qrule->n_points(); _qp++) | ||
ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar); | ||
} | ||
} | ||
} | ||
|
||
void | ||
NonlocalIntegratedBC::computeNonlocalJacobian() | ||
{ | ||
DenseMatrix<Number> & keg = _assembly.jacobianBlockNonlocal(_var.number(), _var.number()); | ||
// compiling set of global IDs for the local DOFs on the element | ||
std::set<dof_id_type> local_dofindices(_var.dofIndices().begin(), _var.dofIndices().end()); | ||
// storing the global IDs for all the DOFs of the variable | ||
const std::vector<dof_id_type> & var_alldofindices = _var.allDofIndices(); | ||
unsigned int n_total_dofs = var_alldofindices.size(); | ||
|
||
for (_k = 0; _k < n_total_dofs; _k++) // looping order for _i & _k are reversed for performance improvement | ||
{ | ||
// eliminating the local components | ||
auto it = local_dofindices.find(var_alldofindices[_k]); | ||
if (it == local_dofindices.end()) | ||
{ | ||
getUserObjectJacobian(_var.number(), var_alldofindices[_k]); | ||
// skip global DOFs that do not contribute to the jacobian | ||
if (!globalDoFEnabled(_var, var_alldofindices[_k])) | ||
continue; | ||
|
||
for (_i = 0; _i < _test.size(); _i++) | ||
for (_qp = 0; _qp < _qrule->n_points(); _qp++) | ||
keg(_i, _k) += _JxW[_qp] * _coord[_qp] * computeQpNonlocalJacobian(var_alldofindices[_k]); | ||
} | ||
} | ||
} | ||
|
||
void | ||
NonlocalIntegratedBC::computeNonlocalOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (jvar == _var.number()) | ||
computeNonlocalJacobian(); | ||
else | ||
{ | ||
MooseVariable & jv = _sys.getVariable(_tid, jvar); | ||
DenseMatrix<Number> & keg = _assembly.jacobianBlockNonlocal(_var.number(), jvar); | ||
// compiling set of global IDs for the local DOFs on the element | ||
std::set<dof_id_type> local_dofindices(jv.dofIndices().begin(), jv.dofIndices().end()); | ||
// storing the global IDs for all the DOFs of the variable | ||
const std::vector<dof_id_type> & jv_alldofindices = jv.allDofIndices(); | ||
unsigned int n_total_dofs = jv_alldofindices.size(); | ||
|
||
for (_k = 0; _k < n_total_dofs; _k++) // looping order for _i & _k are reversed for performance improvement | ||
{ | ||
// eliminating the local components | ||
auto it = local_dofindices.find(jv_alldofindices[_k]); | ||
if (it == local_dofindices.end()) | ||
{ | ||
getUserObjectJacobian(jvar, jv_alldofindices[_k]); | ||
// skip global DOFs that do not contribute to the jacobian | ||
if (!globalDoFEnabled(jv, jv_alldofindices[_k])) | ||
continue; | ||
|
||
for (_i = 0; _i < _test.size(); _i++) | ||
for (_qp = 0; _qp < _qrule->n_points(); _qp++) | ||
keg(_i, _k) += _JxW[_qp] * _coord[_qp] * computeQpNonlocalOffDiagJacobian(jvar, jv_alldofindices[_k]); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.