Skip to content

Commit

Permalink
Testing the concept of nonlocal jacobian contribution (idaholab#5913)
Browse files Browse the repository at this point in the history
  • Loading branch information
SudiptaBiswas committed Aug 24, 2016
1 parent ac12e54 commit 7f820c6
Show file tree
Hide file tree
Showing 23 changed files with 795 additions and 40 deletions.
14 changes: 14 additions & 0 deletions framework/include/base/Assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class Assembly
void useFECache(bool fe_cache) { _should_use_fe_cache = fe_cache; }

void prepare();
void prepareNonlocal();

/**
* Used for preparing the dense residual and jacobian blocks for one particular variable.
Expand All @@ -348,6 +349,7 @@ class Assembly
void prepareVariable(MooseVariable * var);
void prepareNeighbor();
void prepareBlock(unsigned int ivar, unsigned jvar, const std::vector<dof_id_type> & dof_indices);
void prepareBlockNonlocal(unsigned int ivar, unsigned jvar, const std::vector<dof_id_type> & dof_indices);
void prepareScalar();
void prepareOffDiagScalar();

Expand Down Expand Up @@ -394,7 +396,9 @@ class Assembly
void setResidualNeighbor(NumericVector<Number> & residual, Moose::KernelType type = Moose::KT_NONTIME);

void addJacobian(SparseMatrix<Number> & jacobian);
void addJacobianNonlocal(SparseMatrix<Number> & jacobian);
void addJacobianBlock(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices);
void addJacobianBlockNonlocal(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices);
void addJacobianNeighbor(SparseMatrix<Number> & jacobian);
void addJacobianNeighbor(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, std::vector<dof_id_type> & neighbor_dof_indices);
void addJacobianScalar(SparseMatrix<Number> & jacobian);
Expand All @@ -405,6 +409,12 @@ class Assembly
*/
void cacheJacobian();

/**
* Takes the values that are currently in _sub_Keg and appends them to the cached values.
*/
void cacheJacobianNonlocal();


/**
* Takes the values that are currently in the neighbor Dense Matrices and appends them to the cached values.
*/
Expand All @@ -421,8 +431,10 @@ class Assembly
DenseVector<Number> & residualBlockNeighbor(unsigned int var_num, Moose::KernelType type = Moose::KT_NONTIME) { return _sub_Rn[static_cast<unsigned int>(type)][var_num]; }

DenseMatrix<Number> & jacobianBlock(unsigned int ivar, unsigned int jvar);
DenseMatrix<Number> & jacobianBlockNonlocal(unsigned int ivar, unsigned int jvar);
DenseMatrix<Number> & jacobianBlockNeighbor(Moose::DGJacobianType type, unsigned int ivar, unsigned int jvar);
void cacheJacobianBlock(DenseMatrix<Number> & jac_block, std::vector<dof_id_type> & idof_indices, std::vector<dof_id_type> & jdof_indices, Real scaling_factor);
void cacheJacobianBlockNonlocal(DenseMatrix<Number> & jac_block, std::vector<dof_id_type> & idof_indices, std::vector<dof_id_type> & jdof_indices, Real scaling_factor);

std::vector<std::pair<MooseVariable *, MooseVariable *> > & couplingEntries() { return _cm_entry; }

Expand Down Expand Up @@ -549,6 +561,7 @@ class Assembly
std::vector<std::pair<MooseVariable *, MooseVariable *> > _cm_entry;
/// Flag that indicates if the jacobian block was used
std::vector<std::vector<unsigned char> > _jacobian_block_used;
std::vector<std::vector<unsigned char> > _jacobian_block_nonlocal_used;
/// Flag that indicates if the jacobian block for neighbor was used
std::vector<std::vector<unsigned char> > _jacobian_block_neighbor_used;
/// DOF map
Expand Down Expand Up @@ -686,6 +699,7 @@ class Assembly

/// jacobian contributions
std::vector<std::vector<DenseMatrix<Number> > > _sub_Kee;
std::vector<std::vector<DenseMatrix<Number> > > _sub_Keg;

/// jacobian contributions from the element and neighbor
std::vector<std::vector<DenseMatrix<Number> > > _sub_Ken;
Expand Down
6 changes: 5 additions & 1 deletion framework/include/base/DisplacedProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ class DisplacedProblem : public SubProblem
virtual void meshChanged() override;

// reinit /////

virtual void prepare(const Elem * elem, THREAD_ID tid) override;
virtual void prepareNonlocal(THREAD_ID tid);
virtual void prepareFace(const Elem * elem, THREAD_ID tid) override;
virtual void prepare(const Elem * elem, unsigned int ivar, unsigned int jvar, const std::vector<dof_id_type> & dof_indices, THREAD_ID tid) override;
virtual void prepareBlockNonlocal(unsigned int ivar, unsigned int jvar, const std::vector<dof_id_type> & dof_indices, THREAD_ID tid);
virtual void prepareAssembly(THREAD_ID tid) override;
virtual void prepareAssemblyNeighbor(THREAD_ID tid);

Expand Down Expand Up @@ -159,11 +160,14 @@ class DisplacedProblem : public SubProblem
virtual void setResidualNeighbor(NumericVector<Number> & residual, THREAD_ID tid) override;

virtual void addJacobian(SparseMatrix<Number> & jacobian, THREAD_ID tid) override;
virtual void addJacobianNonlocal(SparseMatrix<Number> & jacobian, THREAD_ID tid);
virtual void addJacobianNeighbor(SparseMatrix<Number> & jacobian, THREAD_ID tid) override;
virtual void addJacobianBlock(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, THREAD_ID tid) override;
virtual void addJacobianBlockNonlocal(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, THREAD_ID tid);
virtual void addJacobianNeighbor(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, std::vector<dof_id_type> & neighbor_dof_indices, THREAD_ID tid) override;

virtual void cacheJacobian(THREAD_ID tid) override;
virtual void cacheJacobianNonlocal(THREAD_ID tid);
virtual void cacheJacobianNeighbor(THREAD_ID tid) override;
virtual void addCachedJacobian(SparseMatrix<Number> & jacobian, THREAD_ID tid) override;

Expand Down
13 changes: 13 additions & 0 deletions framework/include/base/FEProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ElementUserObject;
class InternalSideUserObject;
class GeneralUserObject;
class Function;
class KernelBase;

// libMesh forward declarations
namespace libMesh
Expand Down Expand Up @@ -255,6 +256,11 @@ class FEProblem :
*/
Order getMaxScalarOrder() const;

/**
* @return Flag indicating nonlocal coupling exists or not.
*/
void checkNonlocalCoupling();

virtual Assembly & assembly(THREAD_ID tid) override { return *_assembly[tid]; }

/**
Expand Down Expand Up @@ -1064,6 +1070,9 @@ class FEProblem :
/// functions
MooseObjectWarehouse<Function> _functions;

/// nonlocal kernels
MooseObjectWarehouse<KernelBase> _nonlocal_kernels;

///@{
/// Initial condition storage
InitialConditionWarehouse _ics;
Expand Down Expand Up @@ -1193,6 +1202,10 @@ class FEProblem :
/// Indicates if the Jacobian was computed
bool _has_jacobian;

/// Indicates if nonlocal coupling is required/exists
bool _requires_nonlocal_coupling;
bool _has_nonlocal_coupling;

SolverParams _solver_params;

/// Determines whether a check to verify an active kernel on every subdomain
Expand Down
13 changes: 11 additions & 2 deletions framework/include/base/MooseVariableBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef MooseArray<std::vector<RealTensor> > VariablePhiSecond;
class Assembly;
class SubProblem;
class SystemBase;

class MooseMesh;

class MooseVariableBase
{
Expand All @@ -70,10 +70,16 @@ class MooseVariableBase
SystemBase & sys() { return _sys; }

/**
* Get the variable number
* Get the variable name
*/
const std::string & name() const;

/**
* Get all global dofindices for the variable
*/
std::vector<dof_id_type> & allDofIndices();
unsigned int totalVarDofs() { return _all_dof_indices.size(); }

/**
* Kind of the variable (Nonlinear, Auxiliary, ...)
*/
Expand Down Expand Up @@ -133,6 +139,9 @@ class MooseVariableBase
/// DOF indices
std::vector<dof_id_type> _dof_indices;

std::vector<dof_id_type> _all_dof_indices;
/// mesh the variable is active in
MooseMesh & _mesh;
/// scaling factor for this variable
Real _scaling_factor;
};
Expand Down
43 changes: 43 additions & 0 deletions framework/include/kernels/NonlocalKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/****************************************************************/
/* 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 NONLOCALKERNEL_H
#define NONLOCALKERNEL_H

#include "Kernel.h"

class NonlocalKernel;

template<>
InputParameters validParams<NonlocalKernel>();

class NonlocalKernel :
public Kernel
{
public:
NonlocalKernel(const InputParameters & parameters);

virtual void computeJacobian();
virtual void computeOffDiagJacobian(unsigned int jvar);

protected:
/// Compute this Kernel's contribution to the Jacobian corresponding to nolocal dof at the current quadrature point
virtual Real computeQpNonlocalJacobian(dof_id_type dof_index);
virtual Real computeQpNonlocalOffDiagJacobian(unsigned int jvar, dof_id_type dof_index);

DenseMatrix<Number> _nonlocal_ke;
unsigned int _k;
};

#endif /* NONLOCALKERNEL_H */
2 changes: 1 addition & 1 deletion framework/include/userobject/ShapeElementUserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ShapeElementUserObject : public ElementUserObject
dof_id_type _j_global;

/// set to true iff the current call of the user object is for the purpose of calculating Jacobians
const bool & _currently_computing_jacobian;
// const bool _currently_computing_jacobian;

private:
const bool _compute_jacobians;
Expand Down

0 comments on commit 7f820c6

Please sign in to comment.