https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
Moose::Kokkos::RPNEvaluator Class Reference

Reverse Polish Notation (RPN) evaluator. More...

#include <KokkosFunctionParser.h>

Classes

struct  Instruction
 RPN instruction. More...
 

Public Member Functions

 RPNEvaluator ()=default
 Default constructor.
 
 RPNEvaluator (const RPNEvaluator &evaluator)
 Copy constructor for parallel dispatch.
 
void init (const RPNBuilder &builder)
 Initialize RPN evaluator from an RPN builder.
 
KOKKOS_FUNCTION Real eval (const Real t, const Real3 p, const unsigned int qp=0, Datum *datum=nullptr) const
 Evaluate RPN at point (t,x,y,z)
 

Private Types

enum class  VariableType { SCALAR , FIELD , MATERIAL , FUNCTION }
 Types of variables. More...
 
using Opcode = RPNBuilder::Opcode
 

Private Attributes

Array< Instruction_rpn
 RPN sequence.
 
Array< Real > _numbers
 Numbers used in the function.
 
Array< Real > _scalars
 Scalar variables used in the function.
 
Array< VariableValue_fields
 Field variables used in the function.
 
Array< MaterialProperty< Real > > _properties
 Material properties used in the function.
 
Array< Function_functions
 Functions used in the function.
 
Array<::Kokkos::pair< VariableType, unsigned int > > _variables
 Types of variables and indices.
 
std::vector< const void * > _pointers
 Pointers to the associated quantities of variables.
 
unsigned int _num_scalars = 0
 Number of scalar variables.
 
unsigned int _num_fields = 0
 Number of field variables.
 
unsigned int _num_properties = 0
 Number of material properties.
 
unsigned int _num_functions = 0
 Number of functions.
 

Static Private Attributes

static constexpr unsigned int _stack_size = 10
 Fixed stack size.
 
static constexpr double _epsilon = 1.0e-12
 Epsilon for equality comparison.
 

Detailed Description

Reverse Polish Notation (RPN) evaluator.

Definition at line 341 of file KokkosFunctionParser.h.

Member Typedef Documentation

◆ Opcode

Definition at line 343 of file KokkosFunctionParser.h.

Member Enumeration Documentation

◆ VariableType

Types of variables.

Enumerator
SCALAR 
FIELD 
MATERIAL 
FUNCTION 

Definition at line 388 of file KokkosFunctionParser.h.

Constructor & Destructor Documentation

◆ RPNEvaluator() [1/2]

Moose::Kokkos::RPNEvaluator::RPNEvaluator ( )
default

Default constructor.

◆ RPNEvaluator() [2/2]

Moose::Kokkos::RPNEvaluator::RPNEvaluator ( const RPNEvaluator evaluator)

Copy constructor for parallel dispatch.

Member Function Documentation

◆ eval()

KOKKOS_FUNCTION Real Moose::Kokkos::RPNEvaluator::eval ( const Real  t,
const Real3  p,
const unsigned int  qp = 0,
Datum datum = nullptr 
) const
inline

Evaluate RPN at point (t,x,y,z)

Parameters
tThe time
pThe location in space (x,y,z)
qpThe local quadrature point index
datumThe Datum object of the current thread
Returns
The evaluated value

Definition at line 485 of file KokkosFunctionParser.h.

486{
487 Real stack[_stack_size];
488
489 // Stack head position
490 unsigned int head = 0;
491
492 for (unsigned int pos = 0; pos < _rpn.size(); ++pos)
493 {
494 KOKKOS_ASSERT(head < _stack_size);
495
496 const auto inst = _rpn[pos];
497
498 switch (_rpn[pos].op)
499 {
500 case Opcode::NUM:
501 stack[head] = _numbers[inst.arg];
502 ++head;
503 break;
504 case Opcode::VAR:
505 if (inst.arg < 3)
506 stack[head] = p(inst.arg);
507 else if (inst.arg == 3)
508 stack[head] = t;
509 else
510 {
511 const auto type = _variables[inst.arg].first;
512 const auto idx = _variables[inst.arg].second;
513
514 switch (type)
515 {
517 stack[head] = _scalars[idx];
518 break;
520 {
521 KOKKOS_ASSERT(datum);
522
523 stack[head] = _fields[idx](*datum, qp);
524 break;
525 }
527 {
528 KOKKOS_ASSERT(datum);
529
530 stack[head] = _properties[idx](*datum, qp);
531 break;
532 }
534 stack[head] = _functions[idx].value(t, p);
535 break;
536 }
537 }
538 ++head;
539 break;
540 case Opcode::NEG:
541 stack[head - 1] = -stack[head - 1];
542 break;
543 case Opcode::NOT:
544 stack[head - 1] = !::Kokkos::round(stack[head - 1]);
545 break;
546 case Opcode::EQ:
547 stack[head - 2] = ::Kokkos::abs(stack[head - 2] - stack[head - 1]) <= _epsilon;
548 --head;
549 break;
550 case Opcode::NEQ:
551 stack[head - 2] = ::Kokkos::abs(stack[head - 2] - stack[head - 1]) > _epsilon;
552 --head;
553 break;
554 case Opcode::AND:
555 stack[head - 2] = ::Kokkos::round(stack[head - 2]) && ::Kokkos::round(stack[head - 1]);
556 --head;
557 break;
558 case Opcode::OR:
559 stack[head - 2] = ::Kokkos::round(stack[head - 2]) || ::Kokkos::round(stack[head - 1]);
560 --head;
561 break;
562 case Opcode::IF:
563 stack[head - 3] = ::Kokkos::round(stack[head - 3]) ? stack[head - 2] : stack[head - 1];
564 head -= 2;
565 break;
566 KOKKOS_FPARSER_COMPARE(LT, <, -_epsilon);
567 KOKKOS_FPARSER_COMPARE(LEQ, <=, _epsilon);
568 KOKKOS_FPARSER_COMPARE(GT, >, _epsilon);
569 KOKKOS_FPARSER_COMPARE(GEQ, >=, -_epsilon);
570 KOKKOS_FPARSER_BINARY(ADD, +);
571 KOKKOS_FPARSER_BINARY(SUB, -);
572 KOKKOS_FPARSER_BINARY(MUL, *);
573 KOKKOS_FPARSER_BINARY(DIV, /);
574 KOKKOS_FPARSER_FUNCTION_1(ABS, abs);
575 KOKKOS_FPARSER_FUNCTION_1(ACOS, acos);
576 KOKKOS_FPARSER_FUNCTION_1(ACOSH, acosh);
577 KOKKOS_FPARSER_FUNCTION_1(ASIN, asin);
578 KOKKOS_FPARSER_FUNCTION_1(ASINH, asinh);
579 KOKKOS_FPARSER_FUNCTION_1(ATAN, atan);
580 KOKKOS_FPARSER_FUNCTION_2(ATAN2, atan2);
581 KOKKOS_FPARSER_FUNCTION_1(ATANH, atanh);
582 KOKKOS_FPARSER_FUNCTION_1(CBRT, cbrt);
583 KOKKOS_FPARSER_FUNCTION_1(CEIL, ceil);
584 KOKKOS_FPARSER_FUNCTION_1(COS, cos);
585 KOKKOS_FPARSER_FUNCTION_1(COSH, cosh);
586 KOKKOS_FPARSER_FUNCTION_INV_1(COT, tan);
587 KOKKOS_FPARSER_FUNCTION_INV_1(CSC, sin);
588 KOKKOS_FPARSER_FUNCTION_1(EXP, exp);
589 KOKKOS_FPARSER_FUNCTION_1(EXP2, exp2);
590 KOKKOS_FPARSER_FUNCTION_1(FLOOR, floor);
591 KOKKOS_FPARSER_FUNCTION_2(HYPOT, hypot);
592 KOKKOS_FPARSER_FUNCTION_1(INT, round);
593 KOKKOS_FPARSER_FUNCTION_1(LOG, log);
594 KOKKOS_FPARSER_FUNCTION_1(LOG2, log2);
595 KOKKOS_FPARSER_FUNCTION_1(LOG10, log10);
596 KOKKOS_FPARSER_FUNCTION_2(MAX, max);
597 KOKKOS_FPARSER_FUNCTION_2(MIN, min);
598 KOKKOS_FPARSER_FUNCTION_2(POW, pow);
599 KOKKOS_FPARSER_FUNCTION_INV_1(SEC, cos);
600 KOKKOS_FPARSER_FUNCTION_1(SIN, sin);
601 KOKKOS_FPARSER_FUNCTION_1(SINH, sinh);
602 KOKKOS_FPARSER_FUNCTION_1(SQRT, sqrt);
603 KOKKOS_FPARSER_FUNCTION_1(TAN, tan);
604 KOKKOS_FPARSER_FUNCTION_1(TANH, tanh);
605 KOKKOS_FPARSER_FUNCTION_1(TRUNC, trunc);
606 }
607 }
608
609 KOKKOS_ASSERT(head == 1);
610
611 return stack[head - 1];
612}
KOKKOS_FUNCTION T & first() const
Get the first element.
Array<::Kokkos::pair< VariableType, unsigned int > > _variables
Types of variables and indices.
Array< Function > _functions
Functions used in the function.
Array< Instruction > _rpn
RPN sequence.
Array< Real > _numbers
Numbers used in the function.
Array< MaterialProperty< Real > > _properties
Material properties used in the function.
Array< VariableValue > _fields
Field variables used in the function.
static constexpr double _epsilon
Epsilon for equality comparison.
Array< Real > _scalars
Scalar variables used in the function.
static constexpr unsigned int _stack_size
Fixed stack size.
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by KokkosParsedMaterial::computeQpProperties(), KokkosParsedAux::computeValue(), and KokkosParsedFunction::value().

◆ init()

void Moose::Kokkos::RPNEvaluator::init ( const RPNBuilder builder)

Initialize RPN evaluator from an RPN builder.

Parameters
builderThe RPN builder

Member Data Documentation

◆ _epsilon

constexpr double Moose::Kokkos::RPNEvaluator::_epsilon = 1.0e-12
staticconstexprprivate

Epsilon for equality comparison.

Definition at line 453 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _fields

Array<VariableValue> Moose::Kokkos::RPNEvaluator::_fields
private

Field variables used in the function.

Definition at line 411 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _functions

Array<Function> Moose::Kokkos::RPNEvaluator::_functions
private

Functions used in the function.

Definition at line 419 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _num_fields

unsigned int Moose::Kokkos::RPNEvaluator::_num_fields = 0
private

Number of field variables.

Definition at line 436 of file KokkosFunctionParser.h.

◆ _num_functions

unsigned int Moose::Kokkos::RPNEvaluator::_num_functions = 0
private

Number of functions.

Definition at line 444 of file KokkosFunctionParser.h.

◆ _num_properties

unsigned int Moose::Kokkos::RPNEvaluator::_num_properties = 0
private

Number of material properties.

Definition at line 440 of file KokkosFunctionParser.h.

◆ _num_scalars

unsigned int Moose::Kokkos::RPNEvaluator::_num_scalars = 0
private

Number of scalar variables.

Definition at line 432 of file KokkosFunctionParser.h.

◆ _numbers

Array<Real> Moose::Kokkos::RPNEvaluator::_numbers
private

Numbers used in the function.

Definition at line 403 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _pointers

std::vector<const void *> Moose::Kokkos::RPNEvaluator::_pointers
private

Pointers to the associated quantities of variables.

Definition at line 427 of file KokkosFunctionParser.h.

◆ _properties

Array<MaterialProperty<Real> > Moose::Kokkos::RPNEvaluator::_properties
private

Material properties used in the function.

Definition at line 415 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _rpn

Array<Instruction> Moose::Kokkos::RPNEvaluator::_rpn
private

RPN sequence.

Definition at line 399 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _scalars

Array<Real> Moose::Kokkos::RPNEvaluator::_scalars
private

Scalar variables used in the function.

Definition at line 407 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _stack_size

constexpr unsigned int Moose::Kokkos::RPNEvaluator::_stack_size = 10
staticconstexprprivate

Fixed stack size.

Definition at line 449 of file KokkosFunctionParser.h.

Referenced by eval().

◆ _variables

Array<::Kokkos::pair<VariableType, unsigned int> > Moose::Kokkos::RPNEvaluator::_variables
private

Types of variables and indices.

Definition at line 423 of file KokkosFunctionParser.h.

Referenced by eval().


The documentation for this class was generated from the following file: