Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
stdfunction_operator.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2023, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <functional>
16 
17 #include "mfem.hpp"
18 
19 namespace serac::mfem_ext {
20 
31 class StdFunctionOperator : public mfem::Operator {
32 public:
38  StdFunctionOperator(int n) : mfem::Operator(n) {}
39 
46  StdFunctionOperator(int h, int w) : mfem::Operator(h, w) {}
47 
54  StdFunctionOperator(int n, std::function<void(const mfem::Vector&, mfem::Vector&)> function)
55  : mfem::Operator(n), function_(function)
56  {
57  }
58 
66  StdFunctionOperator(int h, int w, std::function<void(const mfem::Vector&, mfem::Vector&)> function)
67  : mfem::Operator(h, w), function_(function)
68  {
69  }
70 
79  StdFunctionOperator(int n, std::function<void(const mfem::Vector&, mfem::Vector&)> function,
80  std::function<mfem::Operator&(const mfem::Vector&)> jacobian)
81  : mfem::Operator(n), function_(function), jacobian_(jacobian)
82  {
83  }
84 
94  StdFunctionOperator(int h, int w, std::function<void(const mfem::Vector&, mfem::Vector&)> function,
95  std::function<mfem::Operator&(const mfem::Vector&)> jacobian)
96  : mfem::Operator(h, w), function_(function), jacobian_(jacobian)
97  {
98  }
99 
106  void Mult(const mfem::Vector& k, mfem::Vector& y) const { function_(k, y); };
107 
114  mfem::Operator& GetGradient(const mfem::Vector& k) const { return jacobian_(k); };
115 
116 private:
120  std::function<void(const mfem::Vector&, mfem::Vector&)> function_;
121 
125  std::function<mfem::Operator&(const mfem::Vector&)> jacobian_;
126 };
127 
128 } // namespace serac::mfem_ext
StdFunctionOperator is a class wrapping mfem::Operator so that the user can use std::function to defi...
StdFunctionOperator(int n, std::function< void(const mfem::Vector &, mfem::Vector &)> function)
Constructor for a square StdFunctionOperator that only defines mfem::Operator::Mult.
StdFunctionOperator(int n)
Default constructor for creating a square uninitialized StdFunctionOperator.
StdFunctionOperator(int h, int w, std::function< void(const mfem::Vector &, mfem::Vector &)> function, std::function< mfem::Operator &(const mfem::Vector &)> jacobian)
Constructor for a rectangular StdFunctionOperator that defines mfem::Operator::Mult and mfem::Operato...
StdFunctionOperator(int h, int w)
Default constructor for creating a rectangular uninitialized StdFunctionOperator.
StdFunctionOperator(int n, std::function< void(const mfem::Vector &, mfem::Vector &)> function, std::function< mfem::Operator &(const mfem::Vector &)> jacobian)
Constructor for a square StdFunctionOperator that defines mfem::Operator::Mult and mfem::Operator::Ge...
mfem::Operator & GetGradient(const mfem::Vector &k) const
The underlying GetGradient (e.g. residual jacobian evaluation) method.
StdFunctionOperator(int h, int w, std::function< void(const mfem::Vector &, mfem::Vector &)> function)
Constructor for a rectangular StdFunctionOperator that only defines mfem::Operator::Mult.
void Mult(const mfem::Vector &k, mfem::Vector &y) const
The underlying mult (e.g. residual evaluation) method.