MFEM  v3.3
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tassign.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_TEMPLATE_ASSIGN
13 #define MFEM_TEMPLATE_ASSIGN
14 
15 #include "../config/tconfig.hpp"
16 
17 namespace mfem
18 {
19 
20 // Assignment operations
21 
22 struct AssignOp
23 {
24  enum Type
25  {
26  Set, // a = b
27  Add, // a += b
28  Mult, // a *= b
29  Div, // a /= b
30  rDiv // a = b/a
31  };
32 };
33 
34 namespace internal
35 {
36 
37 template <AssignOp::Type Op>
38 struct AssignOp_Impl;
39 
40 template <>
41 struct AssignOp_Impl<AssignOp::Set>
42 {
43  template <typename lvalue_t, typename rvalue_t>
44  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
45  {
46  return (a = b);
47  }
48 };
49 
50 template <>
51 struct AssignOp_Impl<AssignOp::Add>
52 {
53  template <typename lvalue_t, typename rvalue_t>
54  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
55  {
56  MFEM_FLOPS_ADD(1);
57  return (a += b);
58  }
59 };
60 
61 template <>
62 struct AssignOp_Impl<AssignOp::Mult>
63 {
64  template <typename lvalue_t, typename rvalue_t>
65  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
66  {
67  MFEM_FLOPS_ADD(1);
68  return (a *= b);
69  }
70 };
71 
72 template <>
73 struct AssignOp_Impl<AssignOp::Div>
74 {
75  template <typename lvalue_t, typename rvalue_t>
76  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
77  {
78  MFEM_FLOPS_ADD(1);
79  return (a /= b);
80  }
81 };
82 
83 template <>
84 struct AssignOp_Impl<AssignOp::rDiv>
85 {
86  template <typename lvalue_t, typename rvalue_t>
87  static inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
88  {
89  MFEM_FLOPS_ADD(1);
90  return (a = b/a);
91  }
92 };
93 
94 } // namespace mfem::internal
95 
96 template <AssignOp::Type Op, typename lvalue_t, typename rvalue_t>
97 inline lvalue_t &Assign(lvalue_t &a, const rvalue_t &b)
98 {
100 }
101 
102 } // namespace mfem
103 
104 #endif // MFEM_TEMPLATE_ASSIGN
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Definition: table.cpp:468
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Definition: densemat.cpp:2807
lvalue_t & Assign(lvalue_t &a, const rvalue_t &b)
Definition: tassign.hpp:97