Skip to content

Commit

Permalink
more work on plasticity
Browse files Browse the repository at this point in the history
r1900
  • Loading branch information
friedmud authored and permcody committed Feb 14, 2014
1 parent 82c7934 commit 0d86cfc
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 4 deletions.
43 changes: 43 additions & 0 deletions framework/include/bcs/SinNeumannBC.h
@@ -0,0 +1,43 @@
#ifndef SINNEUMANNBC_H
#define SINNEUMANNBC_H

#include "BoundaryCondition.h"


//Forward Declarations
class SinNeumannBC;

template<>
InputParameters validParams<SinNeumannBC>();

/**
* Implements a simple constant SinNeumann BC where grad(u)=value on the boundary.
* Uses the term produced from integrating the diffusion operator by parts.
*/
class SinNeumannBC : public BoundaryCondition
{
public:

/**
* Factory constructor, takes parameters so that all derived classes can be built using the same
* constructor.
*/
SinNeumannBC(std::string name, MooseSystem & moose_system, InputParameters parameters);

virtual ~SinNeumannBC() {}

protected:
virtual Real computeQpResidual();

private:
Real _initial;
Real _final;
Real _duration;

/**
* Value of grad(u) on the boundary.
*/
Real _value;
};

#endif //SINNEUMANNBC_H
94 changes: 92 additions & 2 deletions framework/include/utils/ColumnMajorMatrix.h
Expand Up @@ -86,6 +86,31 @@ class ColumnMajorMatrix
*/
void setDiag(Real value);

/**
* The trace of the CMM.
*/
Real tr();

/**
* Zero the matrix.
*/
void zero();

/**
* Turn the matrix into an identity matrix.
*/
void identity();

/**
* Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
*/
Real doubleContraction(const ColumnMajorMatrix & rhs);

/**
* The Euclidean norm of the matrix.
*/
Real norm();

/**
* Sets the values in _this_ tensor to the values on the RHS.
* Will also reshape this tensor if necessary.
Expand Down Expand Up @@ -151,6 +176,11 @@ class ColumnMajorMatrix
*/
ColumnMajorMatrix & operator*=(Real scalar);

/**
* Scalar Division plus assignment
*/
ColumnMajorMatrix & operator/=(Real scalar);

/**
* Scalar Addition plus assignment
*/
Expand Down Expand Up @@ -244,10 +274,62 @@ ColumnMajorMatrix::transpose()
inline void
ColumnMajorMatrix::setDiag(Real value)
{
mooseAssert(_n_rows == _n_cols, "Cannot set the diagonal of a non-square matrix!");

for(unsigned int i=0; i<_n_rows; i++)
(*this)(i,i) = value;
}

inline Real
ColumnMajorMatrix::tr()
{
mooseAssert(_n_rows == _n_cols, "Cannot find the trace of a non-square matrix!");

Real trace = 0;

for(unsigned int i=0; i<_n_rows; i++)
trace += (*this)(i,i);

return trace;
}

inline void
ColumnMajorMatrix::zero()
{
for(unsigned int i=0; i<_n_entries; i++)
_values[i] = 0;
}

inline void
ColumnMajorMatrix::identity()
{
mooseAssert(_n_rows == _n_cols, "Cannot set the diagonal of a non-square matrix!");

zero();

for(unsigned int i=0; i<_n_rows; i++)
(*this)(i,i) = 1;
}

inline Real
ColumnMajorMatrix::doubleContraction(const ColumnMajorMatrix & rhs)
{
mooseAssert(_n_rows == rhs._n_rows && _n_cols == rhs._n_cols, "Matrices must be the same shape for a double contraction!");

Real value = 0;

for(unsigned int j=0; j<_n_cols; j++)
for(unsigned int i=0; i<_n_rows; i++)
value += (*this)(i,j) * rhs(j, i);

return value;
}

inline Real
ColumnMajorMatrix::norm()
{
return std::sqrt(doubleContraction(*this));
}

inline ColumnMajorMatrix &
ColumnMajorMatrix::operator=(const TypeTensor<Real> & rhs)
Expand Down Expand Up @@ -333,7 +415,7 @@ ColumnMajorMatrix::operator*(const ColumnMajorMatrix & rhs) const
mooseAssert(_n_cols == rhs._n_rows, "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");

ColumnMajorMatrix ret_matrix(_n_rows, rhs._n_cols);

for (unsigned int i=0; i<ret_matrix._n_rows; ++i)
for (unsigned int j=0; j<ret_matrix._n_cols; ++j)
for (unsigned int k=0; k<_n_cols; ++k)
Expand Down Expand Up @@ -369,7 +451,7 @@ ColumnMajorMatrix::operator+=(const ColumnMajorMatrix & rhs)
inline ColumnMajorMatrix &
ColumnMajorMatrix::operator-=(const ColumnMajorMatrix & rhs)
{
mooseAssert((_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols), "Cannot perform matrix addition and assignment! The shapes of the two operands are not compatible!");
mooseAssert((_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols), "Cannot perform matrix subtraction and assignment! The shapes of the two operands are not compatible!");

for(unsigned int i=0; i<_n_entries; i++)
_values[i] -= rhs._values[i];
Expand All @@ -396,6 +478,14 @@ ColumnMajorMatrix::operator*=(Real scalar)
return *this;
}

inline ColumnMajorMatrix &
ColumnMajorMatrix::operator/=(Real scalar)
{
for(unsigned int i=0; i<_n_entries; i++)
_values[i] /= scalar;
return *this;
}

inline ColumnMajorMatrix &
ColumnMajorMatrix::operator+=(Real scalar)
{
Expand Down
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -8,6 +8,7 @@
#include "BCFactory.h"
#include "DirichletBC.h"
#include "SinDirichletBC.h"
#include "SinNeumannBC.h"
#include "NeumannBC.h"
#include "VectorNeumannBC.h"
#include "VacuumBC.h"
Expand Down Expand Up @@ -115,6 +116,7 @@ Moose::registerObjects()

BCFactory::instance()->registerBC<DirichletBC>("DirichletBC");
BCFactory::instance()->registerBC<SinDirichletBC>("SinDirichletBC");
BCFactory::instance()->registerBC<SinNeumannBC>("SinNeumannBC");
BCFactory::instance()->registerBC<NeumannBC>("NeumannBC");
BCFactory::instance()->registerBC<VectorNeumannBC>("VectorNeumannBC");
BCFactory::instance()->registerBC<VacuumBC>("VacuumBC");
Expand Down
34 changes: 34 additions & 0 deletions framework/src/bcs/SinNeumannBC.C
@@ -0,0 +1,34 @@
#include "SinNeumannBC.h"

#include "MooseSystem.h"

template<>
InputParameters validParams<SinNeumannBC>()
{
InputParameters params = validParams<BoundaryCondition>();
params.set<Real>("initial")=0.0;
params.set<Real>("final")=0.0;
params.set<Real>("duration")=0.0;
return params;
}

SinNeumannBC::SinNeumannBC(std::string name, MooseSystem & moose_system, InputParameters parameters)
:BoundaryCondition(name, moose_system, setIntegratedParam(parameters, true)),
_initial(_parameters.get<Real>("initial")),
_final(_parameters.get<Real>("final")),
_duration(_parameters.get<Real>("duration"))
{}

Real
SinNeumannBC::computeQpResidual()
{
Real value;

if(_moose_system._t < _duration)
value = _initial + (_final-_initial) * std::sin((0.5/_duration) * libMesh::pi * _moose_system._t);
else
value = _final;

return -_phi[_i][_qp]*value;
}

4 changes: 2 additions & 2 deletions framework/src/materials/Material.C
Expand Up @@ -272,7 +272,7 @@ Material::materialReinit()
std::map<std::string, MooseArray<ColumnMajorMatrix> >::iterator column_major_matrix_it_end = _column_major_matrix_props_old.end();

for(;column_major_matrix_it!=column_major_matrix_it_end;++column_major_matrix_it)
column_major_matrix_it->second.resize(qpoints,0);
column_major_matrix_it->second.resize(qpoints);
}

{
Expand Down Expand Up @@ -305,7 +305,7 @@ Material::materialReinit()
std::map<std::string, MooseArray<ColumnMajorMatrix> >::iterator column_major_matrix_it_end = _column_major_matrix_props_older.end();

for(;column_major_matrix_it!=column_major_matrix_it_end;++column_major_matrix_it)
column_major_matrix_it->second.resize(qpoints,0);
column_major_matrix_it->second.resize(qpoints);
}

}
Expand Down

0 comments on commit 0d86cfc

Please sign in to comment.