ug4
Loading...
Searching...
No Matches
linker_traits.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER_TRAITS__
34#define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER_TRAITS__
35
36#include "common/common.h"
37
38namespace ug{
39
41// Linker Traits to allow generic programming
43
45template <typename TData, typename TDataIn, typename TRet = TData>
47{
49 static void mult_add(TData& out, const TData& in1, const TDataIn& s);
50};
51
52template <>
54{
55 static void mult_add(number& out, const number& in1, const number& s)
56 {
57 out += in1 * s;
58 }
59};
60
61template <std::size_t dim>
63{
64 static void mult_add(MathVector<dim>& out,
65 const MathVector<dim>& in1,
66 const number& s)
67 {
68 VecScaleAppend(out, s, in1);
69 }
70};
71
72template <std::size_t dim>
73struct linker_traits< MathVector<dim>, MathMatrix<dim,dim> >
74{
75 static void mult_add(MathVector<dim>& out,
76 const MathVector<dim>& in1,
77 const MathMatrix<dim,dim>& s)
78 {
79 MatVecMultAppend(out, s, in1);
80 }
81};
82
83template <std::size_t dim>
85{
86 static void mult_add(number& out,
87 const MathVector<dim>& in1,
88 const MathVector<dim>& s)
89 {
90 out = VecDot(s, in1);
91 }
92};
93
94template <std::size_t dim>
95struct linker_traits< MathMatrix<dim,dim>, number >
96{
97 static void mult_add(MathMatrix<dim,dim>& out,
98 const MathMatrix<dim,dim>& in1,
99 const number& s)
100 {
101 MatScaleAppend(out, s, in1);
102 }
103};
104
105template <std::size_t dim>
107{
108 static void mult_add(MathTensor<4,dim>& out,
109 const MathTensor<4, dim>& in1,
110 const number& s)
111 {
112 out = in1;
113 UG_THROW("linker_traits for MathTensor4 not implemented");
114 }
115};
116
117} // end namespace ug
118
119#endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER_TRAITS__ */
parameterString s
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Tensor of rank TRank and N entries.
Definition math_tensor.h:56
a mathematical Vector with N entries.
Definition math_vector.h:97
void MatScaleAppend(matrix_t &mOut, typename matrix_t::value_type s, const matrix_t &m)
scales a matrix_t and adds to result to a second matrix
Definition math_matrix_functions_common_impl.hpp:329
#define UG_THROW(msg)
Definition error.h:57
double number
Definition types.h:124
void MatVecMultAppend(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication adding to a second vector.
Definition math_matrix_vector_functions_common_impl.hpp:70
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
Scales a Vector and adds it to a second vector.
Definition math_vector_functions_common_impl.hpp:126
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition math_vector_functions_common_impl.hpp:385
the ug namespace
static void mult_add(MathMatrix< dim, dim > &out, const MathMatrix< dim, dim > &in1, const number &s)
Definition linker_traits.h:97
static void mult_add(MathTensor< 4, dim > &out, const MathTensor< 4, dim > &in1, const number &s)
Definition linker_traits.h:108
static void mult_add(MathVector< dim > &out, const MathVector< dim > &in1, const MathMatrix< dim, dim > &s)
Definition linker_traits.h:75
static void mult_add(number &out, const MathVector< dim > &in1, const MathVector< dim > &s)
Definition linker_traits.h:86
static void mult_add(MathVector< dim > &out, const MathVector< dim > &in1, const number &s)
Definition linker_traits.h:64
static void mult_add(number &out, const number &in1, const number &s)
Definition linker_traits.h:55
Linker Traits.
Definition linker_traits.h:47
static void mult_add(TData &out, const TData &in1, const TDataIn &s)
computes out += s * in1 (with appropriate '*')