15template<
typename TDataType,
typename TParamVector,
typename TStateVector
16 ,
int state_size,
int param_size>
17class DiffusionFunctional
20 TDataType operator() (TParamVector& vparam, TStateVector& uu)
22 MFEM_ASSERT(state_size==4,
"ExampleFunctor state_size should be equal to 4!");
23 MFEM_ASSERT(param_size==2,
"ExampleFunctor param_size should be equal to 2!");
24 auto kappa = vparam[0];
25 auto load = vparam[1];
26 TDataType rez =
kappa*(uu[0]*uu[0]+uu[1]*uu[1]+uu[2]*uu[2])/2.0 - load*uu[3];
32template<
typename TDataType,
typename TParamVector,
typename TStateVector,
33 int residual_size,
int state_size,
int param_size>
34class DiffusionResidual
37 void operator ()(TParamVector& vparam, TStateVector& uu, TStateVector& rr)
39 MFEM_ASSERT(residual_size==4,
40 "DiffusionResidual residual_size should be equal to 4!");
41 MFEM_ASSERT(state_size==4,
"ExampleFunctor state_size should be equal to 4!");
42 MFEM_ASSERT(param_size==2,
"ExampleFunctor param_size should be equal to 2!");
43 auto kappa = vparam[0];
44 auto load = vparam[1];
46 rr[0] =
kappa * uu[0];
47 rr[1] =
kappa * uu[1];
48 rr[2] =
kappa * uu[2];
53int main(
int argc,
char *argv[])
56#ifdef MFEM_USE_ADFORWARD
57 std::cout<<
"MFEM_USE_ADFORWARD == true"<<std::endl;
59 std::cout<<
"MFEM_USE_ADFORWARD == false"<<std::endl;
62#ifdef MFEM_USE_CALIPER
63 cali::ConfigManager mgr;
67#ifdef MFEM_USE_CALIPER
68 const char* cali_config =
"runtime-report";
89 MFEM_PERF_BEGIN(
"Grad");
90 adf.
Grad(param,state,rr0);
91 MFEM_PERF_END(
"Grad");
92 MFEM_PERF_BEGIN(
"Hessian");
94 MFEM_PERF_END(
"Hessian");
96 std::cout<<
"FunctionAutoDiff"<<std::endl;
97 std::cout<< adf.
Eval(param,state)<<std::endl;
102 MFEM_PERF_BEGIN(
"Jacobian");
104 MFEM_PERF_END(
"Jacobian");
106 std::cout<<
"ResidualAutoDiff"<<std::endl;
107 hh1.
Print(std::cout);
115 auto kappa = vparam[0];
116 auto load = vparam[1];
118 vres[0] =
kappa * uu[0];
119 vres[1] =
kappa * uu[1];
120 vres[2] =
kappa * uu[2];
125 MFEM_PERF_BEGIN(
"JacobianV");
128 MFEM_PERF_END(
"JacobianV");
129 std::cout<<
"LambdaAutoDiff"<<std::endl;
130 hh1.
Print(std::cout);
142 vres[0] =
kappa * uu[0];
143 vres[1] =
kappa * uu[1];
144 vres[2] =
kappa * uu[2];
149 MFEM_PERF_BEGIN(
"Jacobian1");
151 MFEM_PERF_END(
"Jacobian1");
152 std::cout<<
"LambdaAutoDiff 01"<<std::endl;
153 hh1.
Print(std::cout);
155#ifdef MFEM_USE_CALIPER
Data type dense matrix using column-major storage.
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
void Hessian(mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
real_t Eval(const mfem::Vector &vparam, mfem::Vector &uu)
void Grad(const mfem::Vector &vparam, mfem::Vector &uu, mfem::Vector &rr)
void Jacobian(mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
Templated vector data type.
void Jacobian(mfem::Vector &vparam, mfem::Vector &vstate, mfem::DenseMatrix &jac)
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.