Skip to content

Commit

Permalink
Add separate assembly case for two scalar variables
Browse files Browse the repository at this point in the history
Add a bunch more comments to document which terms are done where
Verified with test case
  • Loading branch information
ttruster committed Jan 11, 2023
1 parent cfd5462 commit b3cbe43
Show file tree
Hide file tree
Showing 11 changed files with 884 additions and 59 deletions.
2 changes: 1 addition & 1 deletion framework/include/kernels/KernelScalarBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class KernelScalarBase : public Kernel
virtual void computeOffDiagJacobian(unsigned int jvar_num) override;
/**
* Computes jacobian block with respect to a scalar variable
* @param jvar, the number of the (other) scalar variable
* @param svar, the number of the (other) scalar variable
*/
void computeOffDiagJacobianScalar(unsigned int svar_num) override;

Expand Down
13 changes: 8 additions & 5 deletions framework/src/kernels/KernelScalarBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,23 @@ KernelScalarBase::computeOffDiagJacobianScalar(const unsigned int svar_num)
}
else if (svar_num == _kappa_var) // column for this kernel's scalar variable
{
// Perform assembly using method in Kernel
// Perform assembly using method in Kernel; works for simple cases but not general
// Kernel::computeOffDiagJacobianScalar(svar_num); // d-_var-residual / d-_kappa
// Perform assembly using DenseMatrix like d-_kappa_var-residual / d-_var
// Perform assembly using local_ke like d-_kappa_var-residual / d-_var
computeOffDiagJacobianScalarLocal(svar_num); // d-_var-residual / d-_kappa
computeScalarJacobian(); // d-_kappa-residual / d-_kappa
}
else // some other column for scalar variable
{
Kernel::computeOffDiagJacobianScalar(svar_num); // d-_var-residual / d-jvar
computeScalarOffDiagJacobianScalar(svar_num); // d-_kappa-residual / d-jvar
// Perform assembly using method in Kernel; works for simple cases but not general
// Kernel::computeOffDiagJacobianScalar(svar_num); // d-_var-residual / d-jvar
// Perform assembly using local_ke like d-_kappa_var-residual / d-_var
computeOffDiagJacobianScalarLocal(svar_num); // d-_var-residual / d-svar
computeScalarOffDiagJacobianScalar(svar_num); // d-_kappa-residual / d-svar
}
}
else
Kernel::computeOffDiagJacobianScalar(svar_num); // d-_var-residual / d-jvar
Kernel::computeOffDiagJacobianScalar(svar_num); // d-_var-residual / d-svar
}

void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
//* 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 "TotalLagrangianStressDivergenceS.h"

// Helpers common to the whole homogenization system
namespace HomogenizationA
{
/// Moose constraint type, for input
const MultiMooseEnum constraintType("strain stress none");
/// Constraint type: stress/PK stress or strain/deformation gradient
enum class ConstraintType
{
Strain,
Stress,
None
};
typedef std::map<std::pair<unsigned int, unsigned int>, std::pair<ConstraintType, const Function *>>
ConstraintMap;
}

/// Total Lagrangian formulation with most homogenization terms (one disp_xyz field and one scalar)
/// The macro_gradient variable is split into two scalars: the first component called '_hvar'
/// herein and all other components called '_avar' herein. For parameter _beta = 0, the primary
/// scalar (_kappa) is _hvar and the coupled scalar is _avar. For parameter _beta = 1, the primary
/// scalar (_kappa) is _avar and the coupled scalar is _hvar. Just like the primary field variable
/// (_var) is either disp_x or disp_y or disp_z depending on _alpha.
///
/// Thus, each instance of HomogenizedTotalLagrangianStressDivergenceA acts on one field variable
/// (_disp_alpha) and one scalar variable (_hvar_beta). The job of the kernel is to assemble the
/// residual of all dofs of _disp_alpha and of all dofs of _hvar_beta (namely, selected rows).
/// Similarly, it assembles the ENTIRE row for _disp_alpha and _hvar_beta (namely the columns
/// from all dofs of all _disp field variables and all dofs of all scalar variables _hvar and
/// _avar). The rows for the other field/scalar variables are handled by other instances of the
/// kernel, which have other values of _alpha AND _beta. The logical checks ensure the proper
/// decomposition of the jobs.
///
/// In summary, for x=disp_x etc. and h=_hvar and a=_avar, then the contributions of the instances are
/// _alpha=0, _beta=0
/// R = [Rx, 00, 00, Rh, 00 ]^T
/// J = [Jxx, Jxy, Jxz, Jxh, 000
/// Jhx, 000, 000, Jhh, Jha]
/// _alpha=1, _beta=0
/// R = [00, Ry, 00, 00, 00 ]^T
/// J = [Jyx, Jyy, Jyz, Jyh, 000
/// 000, Jhy, 000, 000, 000]
/// _alpha=2, _beta=0
/// R = [00, 00, Rz, 00, 00 ]^T
/// J = [Jzx, Jzy, Jzz, Jzh, 000
/// 000, 000, Jhz, 000, 000]
/// _alpha=0, _beta=1
/// R = [00, 00, 00, 00, Ra ]^T
/// J = [000, 000, 000, 000, Jxa
/// Jax, 000, 000, Jah, Jaa]
/// _alpha=1, _beta=1
/// R = [00, 00, 00, 00, 00 ]^T
/// J = [000, 000, 000, 000, Jya
/// 000, Jay, 000, 000, 000]
/// _alpha=2, _beta=1
/// R = [00, 00, 00, 00, 00 ]^T
/// J = [000, 000, 000, 000, Jza
/// 000, 000, Jaz, 000, 000]
///
/// In this manner, the full R and J are obtained with NO duplication of jobs:
/// R = [Rx, Ry, Rz, Rh, Ra ]^T
/// J = [Jxx, Jxy, Jxz, Jxh, Jxa
/// Jxy, Jyy, Jyz, Jyh, Jya
/// Jzx, Jzy, Jzz, Jzh, Jza
/// Jhx, Jhy, Jhz, Jhh, Jha
/// Jax, Jay, Jaz, Jah, Jaa]
///
class HomogenizedTotalLagrangianStressDivergenceA : public TotalLagrangianStressDivergenceS
{
public:
static InputParameters validParams();
HomogenizedTotalLagrangianStressDivergenceA(const InputParameters & parameters);

protected:
// Add overrides to base class contributions to only happen for _beta==0, to happen only once
virtual Real computeQpResidual() override;
virtual Real computeQpJacobianDisplacement(unsigned int alpha, unsigned int beta) override;

/**
* Method for computing the scalar part of residual for _kappa
*/
virtual void computeScalarResidual() override;

/**
* Method for computing the scalar variable part of Jacobian for d-_kappa-residual / d-_kappa
*/
virtual void computeScalarJacobian() override;

/**
* Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar
* jvar is looped over all field variables, which herein is just disp_x and disp_y
*/
virtual void computeScalarOffDiagJacobian(const unsigned int jvar_num) override;

/**
* Method for computing an off-diagonal jacobian component at quadrature points.
*/
virtual Real computeScalarQpOffDiagJacobian(const unsigned int jvar_num) override;

/**
* Method for computing an off-diagonal jacobian component d-_var-residual / d-svar.
* svar is looped over all scalar variables, which herein is just _kappa and _kappa_other
*/
virtual void computeOffDiagJacobianScalarLocal(const unsigned int svar_num) override;

/**
* Method for computing d-_var-residual / d-_svar at quadrature points.
*/
virtual Real computeQpOffDiagJacobianScalar(const unsigned int jvar) override;

/**
* Method for computing an off-diagonal jacobian component d-_kappa-residual / d-svar
* svar is looped over other scalar variables, which herein is just _kappa_other
*/
virtual void computeScalarOffDiagJacobianScalar(const unsigned int svar_num) override;

protected:
/// Which component of the scalar vector residual this constraint is responsible for
const unsigned int _beta;

/// (Pointer to) Scalar variable this kernel operates on
const MooseVariableScalar * const _kappao_var_ptr;

/// The unknown scalar variable ID
const unsigned int _kappao_var;

/// Order of the scalar variable, used in several places
const unsigned int _ko_order;

/// Reference to the current solution at the current quadrature point
const VariableValue & _kappa_other;

/// Type of each constraint (stress or strain) for each component
HomogenizationA::ConstraintMap _cmap;

/// The constraint type; initialize with 'none'
HomogenizationA::ConstraintType _ctype = HomogenizationA::ConstraintType::None;

/// Used internally to iterate over each scalar component
unsigned int _m;
unsigned int _n;
unsigned int _a;
unsigned int _b;
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ typedef std::map<std::pair<unsigned int, unsigned int>, std::pair<ConstraintType
ConstraintMap;
}

/// Total Lagrangian formulation with cross-jacobian homogenization terms
///
/// The total Lagrangian formulation can interact with the homogenization
/// system defined by the HomogenizationConstraintScalarKernel and
/// HomogenizationConstraint user object by providing the
/// correct off-diagonal Jacobian entries.
/// Total Lagrangian formulation with all homogenization terms (one disp_xyz field and macro_gradient scalar)
///
class HomogenizedTotalLagrangianStressDivergenceS : public TotalLagrangianStressDivergenceS
{
Expand All @@ -42,17 +37,18 @@ class HomogenizedTotalLagrangianStressDivergenceS : public TotalLagrangianStress

protected:
/**
* Method for computing the scalar part of residual
* Method for computing the scalar part of residual for _kappa
*/
virtual void computeScalarResidual() override;

/**
* Method for computing the scalar variable part of Jacobian
* Method for computing the scalar variable part of Jacobian for d-_kappa-residual / d-_kappa
*/
virtual void computeScalarJacobian() override;

/**
* Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar
* Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar.
* jvar is looped over all field variables, which herein is just disp_x and disp_y
*/
virtual void computeScalarOffDiagJacobian(const unsigned int jvar_num) override;

Expand All @@ -61,10 +57,14 @@ class HomogenizedTotalLagrangianStressDivergenceS : public TotalLagrangianStress
*/
virtual Real computeScalarQpOffDiagJacobian(const unsigned int jvar_num) override;

/**
* Method for computing an off-diagonal jacobian component d-_var-residual / d-svar.
* svar is looped over all scalar variables, which herein is just _kappa
*/
virtual void computeOffDiagJacobianScalarLocal(const unsigned int svar_num) override;

/**
* Method for computing d-_var-residual / d-_kappa at quadrature points.
* Method for computing d-_var-residual / d-svar at quadrature points.
*/
virtual Real computeQpOffDiagJacobianScalar(const unsigned int jvar) override;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//* 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 "Material.h"

// Helpers common to the whole homogenization system
namespace HomogenizationB
{
/// Moose constraint type, for input
const MultiMooseEnum constraintType("strain stress none");
/// Constraint type: stress/PK stress or strain/deformation gradient
enum class ConstraintType
{
Strain,
Stress,
None
};
typedef std::map<std::pair<unsigned int, unsigned int>, std::pair<ConstraintType, const Function *>>
ConstraintMap;
}

/// Calculate the tensor corresponding to homogenization gradient
///
/// This class takes TWO scalar fields of the correct total size, representing a
/// constant deformation gradient over the domain, and casts them into
/// a RankTwo material property. _macro_gradientA is the 1st component and
/// _macro_gradient is the rest of the components.
///
class ComputeHomogenizedLagrangianStrainA : public Material
{
public:
static InputParameters validParams();
ComputeHomogenizedLagrangianStrainA(const InputParameters & parameters);

protected:
virtual void computeQpProperties() override;

protected:
/// The base name for material properties
const std::string _base_name;

/// Constraint map
HomogenizationB::ConstraintMap _cmap;

/// ScalarVariable with the field
const VariableValue & _macro_gradient;

/// ScalarVariable with 1st component of the field
const VariableValue & _macro_gradientA;

/// Unwrapped into a tensor
MaterialProperty<RankTwoTensor> & _homogenization_contribution;
};

0 comments on commit b3cbe43

Please sign in to comment.