PRISMS-PF  v2.1
pFunction.h
Go to the documentation of this file.
1 // pFunction: An interface for PFunctions in PRISMS-PF
2 // This class is used to declare and load PFunctions from a pre-existing PLibrary
3 // that was created using PRISMS IntegrationTools. The class is a wrapper for the
4 // PFunctions in IntegrationTools so that they can be used for vectorized arrays.
5 // This class also calls the IntegrationTools checkout function in the constructor
6 // to reduce the number of steps the user needs to take. Currently this is only
7 // implemented for scalar functions. Vector functions can be treated component by
8 // component.
9 
10 namespace PFunctions{
11 
12 class pFunction
13 {
14 public:
15  // Constructor, wraps the IntegrationTools checkout function
16  pFunction(std::string function_name);
17 
18  // Returns the value of the function for a given input variable
20 
21  // Returns one of first derivatives of the function for a given input variable
22  scalarvalueType grad(scalarvalueType, unsigned int);
23 
24  // Returns one of the second derivatives of the function for a given input variable
25  scalarvalueType hess(scalarvalueType, unsigned int, unsigned int);
26 
27 private:
28  PRISMS::PFunction<double*, double> fun;
29 };
30 
31 pFunction::pFunction(std::string function_name){
32  PRISMS::PLibrary::checkout(function_name, fun);
33 }
34 
36  scalarvalueType fun_val;
37  for (unsigned i=0; i < var.n_array_elements; i++){
38  fun_val[i] = fun(&var[i]);
39  }
40  return fun_val;
41 
42 }
43 
44 
46  scalarvalueType fun_grad;
47  for (unsigned i=0; i <var.n_array_elements; i++){
48  fun_grad[i] = fun.grad(&var[i],dir);
49  }
50  return fun_grad;
51 
52 }
53 
54 
55 scalarvalueType pFunction::hess(scalarvalueType var,unsigned int dir1, unsigned int dir2){
56  scalarvalueType fun_hess;
57  for (unsigned i=0; i < var.n_array_elements; i++){
58  fun_hess[i] = fun.hess(&var[i],dir1,dir2);
59  }
60  return fun_hess;
61 
62 }
63 
64 }
scalarvalueType grad(scalarvalueType, unsigned int)
Definition: pFunction.h:45
pFunction(std::string function_name)
Definition: pFunction.h:31
PRISMS::PFunction< double *, double > fun
Definition: pFunction.h:28
scalarvalueType val(scalarvalueType)
Definition: pFunction.h:35
dealii::VectorizedArray< double > scalarvalueType
Definition: typeDefs.h:50
scalarvalueType hess(scalarvalueType, unsigned int, unsigned int)
Definition: pFunction.h:55