Skip to content
Permalink
Browse files

Merge pull request #13049 from cticenhour/parsed-curl-13041

Curl Evaluation in MooseParsedVectorFunction
  • Loading branch information...
lindsayad committed Mar 14, 2019
2 parents 8785f41 + 1689d36 commit 2a9bd1c8c3b9115b514f1f2cb9cfebf023bb5925
@@ -77,6 +77,15 @@ class Function : public MooseObject,
*/
virtual RealVectorValue vectorValue(Real t, const Point & p);

/**
* Override this to evaluate the curl of the vector function at a point (t,x,y,z),
* by default this returns a zero vector, you must override it.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A vector of the curl of the function evaluated at the time and location
*/
virtual RealVectorValue vectorCurl(Real t, const Point & p);

/**
* Function objects can optionally provide a gradient at a point. By default
* this returns 0, you must override it.
@@ -35,13 +35,21 @@ class MooseParsedVectorFunction : public Function, public MooseParsedFunctionBas

virtual RealVectorValue vectorValue(Real t, const Point & p) override;

virtual RealVectorValue vectorCurl(Real t, const Point & p) override;

virtual RealGradient gradient(Real t, const Point & p) override;

virtual void initialSetup() override;

protected:
/// Storage for gradient input function(s), in format ready for libMesh
/// Storage for gradient, vector input function(s), in format ready for libMesh
std::string _vector_value;

/// Storage for gradient, curl input function(s), in format ready for libMesh
std::string _curl_value;

/// Pointer to the Parsed function wrapper object for the curl
std::unique_ptr<MooseParsedFunctionWrapper> _curl_function_ptr;
};

#endif // MOOSEPARSEDVECTORFUNCTION_H
@@ -59,6 +59,12 @@ Function::vectorValue(Real /*t*/, const Point & /*p*/)
return RealVectorValue(0, 0, 0);
}

RealVectorValue
Function::vectorCurl(Real /*t*/, const Point & /*p*/)
{
return RealVectorValue(0, 0, 0);
}

Real
Function::integral()
{
@@ -21,6 +21,9 @@ validParams<MooseParsedVectorFunction>()
params.addParam<std::string>("value_x", "0", "x-component of function.");
params.addParam<std::string>("value_y", "0", "y-component of function.");
params.addParam<std::string>("value_z", "0", "z-component of function.");
params.addParam<std::string>("curl_x", "0", "x-component of curl of function.");
params.addParam<std::string>("curl_y", "0", "y-component of curl of function.");
params.addParam<std::string>("curl_z", "0", "z-component of curl of function.");
return params;
}

@@ -29,7 +32,10 @@ MooseParsedVectorFunction::MooseParsedVectorFunction(const InputParameters & par
MooseParsedFunctionBase(parameters),
_vector_value(verifyFunction(std::string("{") + getParam<std::string>("value_x") + "}{" +
getParam<std::string>("value_y") + "}{" +
getParam<std::string>("value_z") + "}"))
getParam<std::string>("value_z") + "}")),
_curl_value(verifyFunction(std::string("{") + getParam<std::string>("curl_x") + "}{" +
getParam<std::string>("curl_y") + "}{" +
getParam<std::string>("curl_z") + "}"))
{
}
@@ -39,6 +45,12 @@ MooseParsedVectorFunction::vectorValue(Real t, const Point & p)
return _function_ptr->evaluate<RealVectorValue>(t, p);
}
RealVectorValue
MooseParsedVectorFunction::vectorCurl(Real t, const Point & p)
{
return _curl_function_ptr->evaluate<RealVectorValue>(t, p);
}
RealGradient
MooseParsedVectorFunction::gradient(Real /*t*/, const Point & /*p*/)
{
@@ -48,13 +60,15 @@ MooseParsedVectorFunction::gradient(Real /*t*/, const Point & /*p*/)
void
MooseParsedVectorFunction::initialSetup()
{
if (!_function_ptr)
{
THREAD_ID tid = 0;
if (isParamValid("_tid"))
tid = getParam<THREAD_ID>("_tid");
THREAD_ID tid = 0;
if (isParamValid("_tid"))
tid = getParam<THREAD_ID>("_tid");
if (!_function_ptr)
_function_ptr = libmesh_make_unique<MooseParsedFunctionWrapper>(
_pfb_feproblem, _vector_value, _vars, _vals, tid);
}
if (!_curl_function_ptr)
_curl_function_ptr = libmesh_make_unique<MooseParsedFunctionWrapper>(
_pfb_feproblem, _curl_value, _vars, _vals, tid);
}
@@ -0,0 +1,32 @@
//* 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

#ifndef VECTORCURLBC_H
#define VECTORCURLBC_H

#include "VectorIntegratedBC.h"

class VectorCurlBC;

template <>
InputParameters validParams<VectorCurlBC>();

class VectorCurlBC : public VectorIntegratedBC
{
public:
VectorCurlBC(const InputParameters & parameters);

protected:
virtual Real computeQpResidual();
virtual Real computeQpJacobian();

Function & _curl_value;
};

#endif // VECTORCURLBC_H
@@ -1,3 +1,12 @@
//* 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

#ifndef VECTORCURLPENALTYDIRICHLETBC_H
#define VECTORCURLPENALTYDIRICHLETBC_H

@@ -0,0 +1,39 @@
//* 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

#include "VectorCurlBC.h"
#include "Function.h"

registerMooseObject("MooseTestApp", VectorCurlBC);

template <>
InputParameters
validParams<VectorCurlBC>()
{
InputParameters params = validParams<VectorIntegratedBC>();
params.addRequiredParam<FunctionName>("curl_value", "Value of field curl on the boundary.");
return params;
}

VectorCurlBC::VectorCurlBC(const InputParameters & parameters)
: VectorIntegratedBC(parameters), _curl_value(getFunction("curl_value"))
{
}

Real
VectorCurlBC::computeQpResidual()
{
return _test[_i][_qp] * _normals[_qp].cross(_curl_value.vectorCurl(_t, _q_point[_qp]));
}

Real
VectorCurlBC::computeQpJacobian()
{
return 0.0;
}
@@ -1,3 +1,12 @@
//* 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

#include "VectorCurlPenaltyDirichletBC.h"
#include "Function.h"

@@ -0,0 +1,64 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
xmin = -1
ymin = -1
elem_type = QUAD9
[]

[Variables]
# u = (y, -x, 0)
[./u]
family = NEDELEC_ONE
order = FIRST
[../]
[]

[Functions]
# Simple "clockwise rotating" field in XY plane. curl(u) = (0, 0, -2)
[./field]
type = ParsedVectorFunction
value_x = 'y'
value_y = '-x'
curl_z = '-2'
[../]
[./ffn_x]
type = ParsedFunction
value = 'y'
[../]
[./ffn_y]
type = ParsedFunction
value = '-x'
[../]
[]

[Kernels]
[./diff]
type = VectorFEWave
variable = u
x_forcing_func = ffn_x
y_forcing_func = ffn_y
[../]
[]

[BCs]
[./top]
type = VectorCurlBC
curl_value = field
variable = u
boundary = 'left right top bottom'
[../]
[]

[Executioner]
type = Steady
solve_type = 'NEWTON'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
Binary file not shown.
@@ -43,4 +43,13 @@
exodiff = 'combined_out.e'
requirement = "The ParsedFunction object shall support the use of functions, scalar values and postprocessor values specified by their names in its expression at the same time."
[../]

[./function_curl]
type = Exodiff
input = function_curl.i
exodiff = 'function_curl_out.e'
abs_zero = 3e-09
requirement = "The Function system shall support the creation of objects that execute a curl of a vector function defined within the input file."
issues = '#13041'
[../]
[]

0 comments on commit 2a9bd1c

Please sign in to comment.
You can’t perform that action at this time.