Skip to content
Permalink
Browse files

Merge pull request #13374 from andrsd/solution-user-object-scalar-sup…

…port

Adding support for scalar variables into SolutionUserObject
  • Loading branch information...
andrsd committed Jun 4, 2019
2 parents 99559df + 1553645 commit 242eae92f411dc306ad672c3fcf2c052b99bec4a
@@ -0,0 +1,13 @@
# SolutionScalarAux

This AuxScalarKernel works in conjunction with a [SolutionUserObject](/SolutionUserObject.md) to set
scalar variable values. These values can be scaled and/or added by utilizing the *scale_factor*
or *add_factor* parameters.

!syntax description /AuxScalarKernels/SolutionScalarAux

!syntax parameters /AuxScalarKernels/SolutionScalarAux

!syntax inputs /AuxScalarKernels/SolutionScalarAux

!syntax children /AuxScalarKernels/SolutionScalarAux
@@ -0,0 +1,47 @@
//* 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 "AuxScalarKernel.h"

class SolutionScalarAux;
class SolutionUserObject;

template <>
InputParameters validParams<SolutionScalarAux>();

/**
* AuxScalarKernel for reading a solution from file.
* Creates a function that extracts values from a solution read from a file,
* via a SolutionUserObject. It is possible to scale and add a constant to the
* solution read.
*/
class SolutionScalarAux : public AuxScalarKernel
{
public:
SolutionScalarAux(const InputParameters & parameters);

virtual void initialSetup() override;

protected:
virtual Real computeValue() override;

/// Reference to the SolutionUserObject storing the solution
const SolutionUserObject & _solution_object;

/// The variable name of interest
std::string _var_name;

/// Multiplier for the solution, the a of ax+b
const Real _scale_factor;

/// Additional factor added to the solution, the b of ax+b
const Real _add_factor;
};
@@ -59,32 +59,42 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
Real pointValueWrapper(Real t,
const Point & p,
const std::string & var_name,
const MooseEnum & weighting_type = weightingType()) const;
const MooseEnum & weighting_type = weightingType(),
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns a value at a specific location and variable (see SolutionFunction)
* @param t The time at which to extract (not used, it is handled automatically when reading the
* data)
* @param p The location at which to return a value
* @param local_var_index The local index of the variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
Real pointValue(Real t, const Point & p, const unsigned int local_var_index) const;
Real pointValue(Real t,
const Point & p,
const unsigned int local_var_index,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns a value at a specific location and variable (see SolutionFunction)
* @param t The time at which to extract (not used, it is handled automatically when reading the
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
Real pointValue(Real t, const Point & p, const std::string & var_name) const;
Real pointValue(Real t,
const Point & p,
const std::string & var_name,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns a value at a specific location and variable for cases where the solution is
@@ -95,10 +105,14 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param local_var_index The local index of the variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
std::map<const Elem *, Real>
discontinuousPointValue(Real t, Point pt, const unsigned int local_var_index) const;
discontinuousPointValue(Real t,
Point pt,
const unsigned int local_var_index,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns a value at a specific location and variable for cases where the solution is
@@ -109,10 +123,14 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
std::map<const Elem *, Real>
discontinuousPointValue(Real t, const Point & p, const std::string & var_name) const;
discontinuousPointValue(Real t,
const Point & p,
const std::string & var_name,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns the gradient at a specific location and variable checking for multiple values and
@@ -122,32 +140,45 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
RealGradient pointValueGradientWrapper(Real t,
const Point & p,
const std::string & var_name,
const MooseEnum & weighting_type = weightingType()) const;
RealGradient
pointValueGradientWrapper(Real t,
const Point & p,
const std::string & var_name,
const MooseEnum & weighting_type = weightingType(),
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns the gradient at a specific location and variable (see SolutionFunction)
* @param t The time at which to extract (not used, it is handled automatically when reading the
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
RealGradient pointValueGradient(Real t, const Point & p, const std::string & var_name) const;
RealGradient
pointValueGradient(Real t,
const Point & p,
const std::string & var_name,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns the gradient at a specific location and variable (see SolutionFunction)
* @param t The time at which to extract (not used, it is handled automatically when reading the
* data)
* @param p The location at which to return a value
* @param local_var_index The local index of the variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
RealGradient pointValueGradient(Real t, Point pt, const unsigned int local_var_index) const;
RealGradient
pointValueGradient(Real t,
Point pt,
const unsigned int local_var_index,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns the gradient at a specific location and variable for cases where the gradient is
@@ -158,10 +189,14 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param var_name The variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
std::map<const Elem *, RealGradient>
discontinuousPointValueGradient(Real t, const Point & p, const std::string & var_name) const;
std::map<const Elem *, RealGradient> discontinuousPointValueGradient(
Real t,
const Point & p,
const std::string & var_name,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Returns the gradient at a specific location and variable for cases where the gradient is
@@ -172,10 +207,14 @@ class SolutionUserObject : public GeneralUserObject
* data)
* @param p The location at which to return a value
* @param local_var_index The local index of the variable to be evaluated
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @return The desired value for the given variable at a location
*/
std::map<const Elem *, RealGradient>
discontinuousPointValueGradient(Real t, Point pt, const unsigned int local_var_index) const;
std::map<const Elem *, RealGradient> discontinuousPointValueGradient(
Real t,
Point pt,
const unsigned int local_var_index,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* Return a value directly from a Node
@@ -193,6 +232,15 @@ class SolutionUserObject : public GeneralUserObject
*/
Real directValue(const Elem * elem, const std::string & var_name) const;

/**
* Returns a value of a global variable
* @param t The time at which to extract (not used, it is handled automatically when reading the
* data)
* @param var_name The variable from which to extract a value
* @return The desired value for the given variable
*/
Real scalarValue(Real t, const std::string & var_name) const;

// Required pure virtual function (not used)
virtual void initialize() override;

@@ -266,43 +314,55 @@ class SolutionUserObject : public GeneralUserObject
* A wrapper method for calling the various MeshFunctions used for reading the data
* @param p The location at which data is desired
* @param local_var_index The local index of the variable to extract data from
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @param func_num The MeshFunction index to use (1 = _mesh_function; 2 = _mesh_function2)
*/
Real evalMeshFunction(const Point & p,
const unsigned int local_var_index,
unsigned int func_num) const;
unsigned int func_num,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* A wrapper method for calling the various MeshFunctions that calls the mesh function
* functionality for evaluating discontinuous shape functions near a face (where it's multivalued)
* @param p The location at which data is desired
* @param local_var_index The local index of the variable to extract data from
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @param func_num The MeshFunction index to use (1 = _mesh_function; 2 = _mesh_function2)
*/
std::map<const Elem *, Real> evalMultiValuedMeshFunction(const Point & p,
const unsigned int local_var_index,
unsigned int func_num) const;
std::map<const Elem *, Real>
evalMultiValuedMeshFunction(const Point & p,
const unsigned int local_var_index,
unsigned int func_num,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* A wrapper method interfacing with the libMesh mesh function for evaluating the gradient
* @param p The location at which data is desired
* @param local_var_index The local index of the variable to extract data from
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @param func_num The MeshFunction index to use (1 = _mesh_function; 2 = _mesh_function2)
*/
RealGradient evalMeshFunctionGradient(const Point & p,
const unsigned int local_var_index,
unsigned int func_num) const;
RealGradient
evalMeshFunctionGradient(const Point & p,
const unsigned int local_var_index,
unsigned int func_num,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/**
* A wrapper method interfacing with the libMesh mesh function that calls the gradient
* functionality for evaluating potentially discontinuous gradients at element's faces (where it's
* multivalued)
* @param p The location at which data is desired
* @param local_var_index The local index of the variable to extract data from
* @param subdomain_ids Subdomains IDs where to look for the value, if nullptr look everywhere
* @param func_num The MeshFunction index to use (1 = _mesh_function; 2 = _mesh_function2)
*/
std::map<const Elem *, RealGradient> evalMultiValuedMeshFunctionGradient(
const Point & p, const unsigned int local_var_index, unsigned int func_num) const;
const Point & p,
const unsigned int local_var_index,
unsigned int func_num,
const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;

/// File type to read (0 = xda; 1 = ExodusII)
MooseEnum _file_type;
@@ -322,8 +382,14 @@ class SolutionUserObject : public GeneralUserObject
/// Stores the local index need by MeshFunction
std::map<std::string, unsigned int> _local_variable_index;

/// Stores flag indicating if the variable is nodal
std::map<std::string, bool> _local_variable_nodal;
/// Stores names of nodal variables
std::vector<std::string> _nodal_variables;

/// Stores names of elemental variables
std::vector<std::string> _elemental_variables;

/// Stores names of scalar variables
std::vector<std::string> _scalar_variables;

/// Current ExodusII time index
int _exodus_time_index;
@@ -412,4 +478,3 @@ class SolutionUserObject : public GeneralUserObject
private:
static Threads::spin_mutex _solution_user_object_mutex;
};

Binary file not shown.
@@ -62,17 +62,12 @@ SolutionAux::initialSetup()

// If there are more than one, throw an error
if (vars.size() > 1)
mooseError("The SolutionUserObject contains multiple variables, in this case the "
"SolutionFunction must specifiy the desired variable in the input file with "
"'from_variable'");
mooseError("The SolutionUserObject contains multiple variables, please specifiy the desired "
"variables in the input file with 'from_variable' parameter.");

// Define the variable
_var_name = vars[0];
}

// Determine if 'from_variable' is elemental, if so then use direct extraction
if (!_solution_object.isVariableNodal(_var_name))
_direct = true;
}

Real

0 comments on commit 242eae9

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