Skip to content

Commit

Permalink
Add a postprocessor that computes the inner product of two variable (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schunert committed Aug 22, 2016
1 parent c5c257e commit e00c7bd
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 0 deletions.
38 changes: 38 additions & 0 deletions framework/include/postprocessors/VariableInnerProduct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/****************************************************************/
/* 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 VARIABLEINNERPRODUCT_H
#define VARIABLEINNERPRODUCT_H

#include "ElementIntegralVariablePostprocessor.h"

//Forward Declarations
class VariableInnerProduct;

template<>
InputParameters validParams<VariableInnerProduct>();

class VariableInnerProduct : public ElementIntegralVariablePostprocessor
{
public:
VariableInnerProduct(const InputParameters & parameters);

protected:
virtual Real computeQpIntegral() override;

/// Holds the values of second_variable at current quadrature points
const VariableValue & _v;
};

#endif //VariableInnerProduct_H
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
#include "ElementL2Difference.h"
#include "TimeExtremeValue.h"
#include "RelativeSolutionDifferenceNorm.h"
#include "VariableInnerProduct.h"

// vector PPS
#include "ConstantVectorPostprocessor.h"
Expand Down Expand Up @@ -624,6 +625,7 @@ registerObjects(Factory & factory)
registerPostprocessor(ElementL2Difference);
registerPostprocessor(TimeExtremeValue);
registerPostprocessor(RelativeSolutionDifferenceNorm);
registerPostprocessor(VariableInnerProduct);

// vector PPS
registerVectorPostprocessor(ConstantVectorPostprocessor);
Expand Down
35 changes: 35 additions & 0 deletions framework/src/postprocessors/VariableInnerProduct.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/****************************************************************/
/* 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 "VariableInnerProduct.h"

template<>
InputParameters validParams<VariableInnerProduct>()
{
InputParameters params = validParams<ElementIntegralVariablePostprocessor>();
params.addRequiredCoupledVar("second_variable", "The name of the second variable in the inner product (variable, second_variable)");
return params;
}

VariableInnerProduct::VariableInnerProduct(const InputParameters & parameters) :
ElementIntegralVariablePostprocessor(parameters),
_v(coupledValue("second_variable"))
{
}

Real
VariableInnerProduct::computeQpIntegral()
{
return _u[_qp] * _v[_qp];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
time,f_dot_f,f_dot_g,norm_f
0,0,0,0
1,0.4,4.1633363423443e-17,0.63245553203368

8 changes: 8 additions & 0 deletions test/tests/postprocessors/variable_inner_product/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Tests]
[./variable_inner_product_test]
type = 'CSVDiff'
input = 'variable_inner_product.i'
csvdiff = 'variable_inner_product.csv'
group = 'requirements'
[../]
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 2
ny = 2
xmin = -1
xmax = 1
ymin = 0
ymax = 1
elem_type = QUAD9
[]

[AuxVariables]
[./f]
order = SECOND
family = LAGRANGE
[./InitialCondition]
type = FunctionIC
function = leg2
[../]
[../]
[./g]
order = FIRST
family = LAGRANGE
[./InitialCondition]
type = FunctionIC
function = leg1
[../]
[../]
[]

[Variables]
[./u]
order = FIRST
family = LAGRANGE
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[]

[Functions]
[./leg1]
type = ParsedFunction
value = 'x'
[../]

[./leg2]
type = ParsedFunction
value = '0.5*(3.0*x*x-1.0)'
[../]
[]

[BCs]
active = 'left right'

[./left]
type = DirichletBC
variable = u
boundary = 1
value = 0
[../]

[./right]
type = DirichletBC
variable = u
boundary = 2
value = 1
[../]
[]

[Executioner]
type = Steady

# Preconditioned JFNK (default)
solve_type = 'PJFNK'

[./Quadrature]
order = fourth
[]
[]

[Postprocessors]
[./f_dot_g]
type = VariableInnerProduct
variable = f
second_variable = g
[../]

[./f_dot_f]
type = VariableInnerProduct
variable = f
second_variable = f
[../]

[./norm_f]
type = ElementL2Norm
variable = f
[../]
[]

[Outputs]
file_base = variable_inner_product
csv = true
[]

0 comments on commit e00c7bd

Please sign in to comment.