Skip to content

Commit

Permalink
#125, started adding kernel and scalarKernel for offDiagonal terms be…
Browse files Browse the repository at this point in the history
…tween variable and scalarVariable.

Runs with offdiagjacscalar branch of https://github.com/pou036/moose.git
  • Loading branch information
pou036 committed May 20, 2017
1 parent 1396931 commit 270a4d0
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
42 changes: 42 additions & 0 deletions include/kernels/RedbackOffDiagonalScalarJacobian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************/
/* 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 REDBACKOFFDIAGONALSCALARJACOBIAN_H
#define REDBACKOFFDIAGONALSCALARJACOBIAN_H

#include "Kernel.h"

class RedbackOffDiagonalScalarJacobian;

template <>
InputParameters validParams<RedbackOffDiagonalScalarJacobian>();

class RedbackOffDiagonalScalarJacobian : public Kernel
{
public:
RedbackOffDiagonalScalarJacobian(const InputParameters & parameters);
virtual ~RedbackOffDiagonalScalarJacobian();

protected:
virtual Real computeQpResidual();
virtual Real computeQpJacobian();
virtual Real computeQpOffDiagJacobian(unsigned int jvar);
unsigned int _sc_var;
const VariableValue & _sc;
unsigned int _z_var;
const VariableValue & _z;

};

#endif /* REDBACKOFFDIAGONALSCALARJACOBIAN_H */
37 changes: 37 additions & 0 deletions include/scalarkernels/RedbackOffDiagonalNonScalar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* REDBACK - Rock mEchanics with Dissipative feedBACKs */
/* */
/* (c) 2014 CSIRO and UNSW Australia */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by CSIRO and UNSW Australia */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef REDBACKOFFDIAGONALNONSCALAR_H
#define REDBACKOFFDIAGONALNONSCALAR_H

#include "ODEKernel.h"

class RedbackOffDiagonalNonScalar;

template <>
InputParameters validParams<RedbackOffDiagonalNonScalar>();

class RedbackOffDiagonalNonScalar : public ODEKernel
{
public:
RedbackOffDiagonalNonScalar(const InputParameters & parameters);

protected:
const VariableValue & _non_scalar_variable;
unsigned int _non_scalar_variable_var;

virtual Real computeQpResidual();
virtual Real computeQpJacobian();
virtual Real computeQpOffDiagJacobian(unsigned int jvar);
};

#endif /* REDBACKOFFDIAGONALNONSCALAR_H */
4 changes: 4 additions & 0 deletions src/base/RedbackApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "RedbackMassDiffusion.h"
#include "RedbackMechDissip.h"
#include "RedbackNavier.h"
#include "RedbackOffDiagonalScalarJacobian.h"
#include "RedbackPoromechanics.h"
#include "RedbackStressDivergenceTensors.h"
#include "RedbackThermalConvection.h"
Expand All @@ -56,6 +57,7 @@

// Scalar Kernels
#include "RedbackContinuation.h"
#include "RedbackOffDiagonalNonScalar.h"

// Dirac Kernels
#include "FunctionPointSource.h"
Expand Down Expand Up @@ -141,6 +143,7 @@ RedbackApp::registerObjects(Factory & factory)
registerKernel(RedbackMassDiffusion);
registerKernel(RedbackMechDissip);
registerKernel(RedbackNavier);
registerKernel(RedbackOffDiagonalScalarJacobian);
registerKernel(RedbackPoromechanics);
registerKernel(RedbackStressDivergenceTensors);
registerKernel(RedbackThermalConvection);
Expand All @@ -150,6 +153,7 @@ RedbackApp::registerObjects(Factory & factory)
registerKernel(RedbackVariableEqualsFunction);

registerScalarKernel(RedbackContinuation);
registerScalarKernel(RedbackOffDiagonalNonScalar);

registerDiracKernel(FunctionPointSource);

Expand Down
61 changes: 61 additions & 0 deletions src/kernels/RedbackOffDiagonalScalarJacobian.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* REDBACK - Rock mEchanics with Dissipative feedBACKs */
/* */
/* (c) 2014 CSIRO and UNSW Australia */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by CSIRO and UNSW Australia */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "RedbackOffDiagonalScalarJacobian.h"

template <>
InputParameters
validParams<RedbackOffDiagonalScalarJacobian>()
{
InputParameters params = validParams<Kernel>();
params.addRequiredCoupledVar("scalar_variable", "Scalar variable coupled into this kernel");
params.addCoupledVar("normal_variable", "Normal variable Z coupled into this kernel");
return params;
}

RedbackOffDiagonalScalarJacobian::RedbackOffDiagonalScalarJacobian(const InputParameters & parameters) :
Kernel(parameters),
_sc_var(coupledScalar("scalar_variable")),
_sc(coupledScalarValue("scalar_variable")),
_z_var(isCoupled("normal_variable")?coupled("normal_variable"):0),
_z(isCoupled("normal_variable")?coupledValue("normal_variable"):_zero)
{
std::cout << "RedbackOffDiagonalScalarJacobian, _sc_var=" << _sc_var << std::endl;
//std::cout << "RedbackOffDiagonalScalarJacobian, _z_var=" << _z_var << std::endl;
}

RedbackOffDiagonalScalarJacobian::~RedbackOffDiagonalScalarJacobian()
{
}

Real
RedbackOffDiagonalScalarJacobian::computeQpResidual()
{
return 0;
}

Real
RedbackOffDiagonalScalarJacobian::computeQpJacobian()
{
return 0;
}

Real
RedbackOffDiagonalScalarJacobian::computeQpOffDiagJacobian(unsigned int jvar)
{
// This code is only called for the (normal) variables
//std::string name = _sys.system().variable_name(jvar); => doens't work :-(
Real x = _u[_qp];
Real y = _sc[_i];
std::cout << "RedbackOffDiagonalScalarJacobian::computeQpOffDiagJacobian, jvar=" << jvar <<", x=" << x << ", y=" << y <<std::endl;
return 0;
}
54 changes: 54 additions & 0 deletions src/scalarkernels/RedbackOffDiagonalNonScalar.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* REDBACK - Rock mEchanics with Dissipative feedBACKs */
/* */
/* (c) 2014 CSIRO and UNSW Australia */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by CSIRO and UNSW Australia */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "RedbackOffDiagonalNonScalar.h"

/**
* This function defines the valid parameters for
* this Kernel and their default values
*/
template <>
InputParameters
validParams<RedbackOffDiagonalNonScalar>()
{
InputParameters params = validParams<ODEKernel>();
params.addRequiredCoupledVar("non_scalar_variable", "The (non scalar) variable to couple");
return params;
}

RedbackOffDiagonalNonScalar::RedbackOffDiagonalNonScalar(const InputParameters & parameters) :
ODEKernel(parameters),
_non_scalar_variable(coupledValue("non_scalar_variable")),
_non_scalar_variable_var(coupled("non_scalar_variable"))
{
}

Real
RedbackOffDiagonalNonScalar::computeQpResidual()
{
return 0.;
}

Real
RedbackOffDiagonalNonScalar::computeQpJacobian()
{
return 0.;
}

Real
RedbackOffDiagonalNonScalar::computeQpOffDiagJacobian(unsigned int jvar)
{
if (jvar == _non_scalar_variable_var)
return 0.;
else
return 0.;
}
96 changes: 96 additions & 0 deletions tests/off_diag_jac_scalar/test_offdiagjacscalar.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[Mesh]
type = GeneratedMesh
dim = 3
[]

[Variables]
[./diffused]
order = FIRST
family = LAGRANGE
[../]
[./z]
[../]
[./y]
family = SCALAR
initial_condition = 1.234
[../]
[]

[Functions]
[./init_gradient]
type = ParsedFunction
value = z
[../]
[]

[Kernels]
active = 'diff td_z'
[./diff]
type = Diffusion
variable = diffused
[../]
[./test]
type = RedbackOffDiagonalScalarJacobian
variable = diffused
normal_variable = z
scalar_variable = y
[../]
[./td_z]
type = TimeDerivative
variable = z
[../]
[]

[BCs]
[./bottom]
type = DirichletBC
variable = diffused
boundary = bottom
value = 1
[../]
[./top]
type = DirichletBC
variable = diffused
boundary = top
value = 0
[../]
[]

[Preconditioning]
[./smp]
type = SMP
full = true
[../]
[]

[Executioner]
type = Transient
num_steps = 1
solve_type = PJFNK
[]

[Outputs]
execute_on = 'timestep_end initial'
exodus = true
[]

[ICs]
[./diffused_init]
function = init_gradient
variable = diffused
type = FunctionIC
[../]
[]

[ScalarKernels]
[./td_y]
variable = y
type = ODETimeDerivative
[../]
[./offidiag]
variable = y
type = RedbackOffDiagonalNonScalar
non_scalar_variable = diffused
[../]
[]

0 comments on commit 270a4d0

Please sign in to comment.