dune-pdelab 2.7-git
Loading...
Searching...
No Matches
selectcomponent.hh
Go to the documentation of this file.
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3#ifndef DUNE_PDELAB_FUNCTION_SELECTCOMPONENT_HH
4#define DUNE_PDELAB_FUNCTION_SELECTCOMPONENT_HH
5
6#include <algorithm>
7#include <cstddef>
8#include <vector>
9
10#include <dune/common/exceptions.hh>
11
13
14namespace Dune {
15 namespace PDELab {
16
18
24 template<typename GF, std::size_t dimR = 1>
26 : public GridFunctionBase<
27 GridFunctionTraits<
28 typename GF::Traits::GridViewType,
29 typename GF::Traits::RangeFieldType, dimR,
30 FieldVector<typename GF::Traits::RangeFieldType, dimR>
31 >,
32 SelectComponentGridFunctionAdapter<GF, dimR>
33 >
34 {
35 public:
36 typedef GridFunctionTraits<
37 typename GF::Traits::GridViewType,
38 typename GF::Traits::RangeFieldType, dimR,
39 FieldVector<typename GF::Traits::RangeFieldType, dimR>
41
42 private:
43 typedef GridFunctionBase<
45 > Base;
46
47 GF& gf;
48 std::size_t remap[dimR];
49
50 void checkRemap() const {
51 for(std::size_t c = 0; c < dimR; ++c)
52 if(remap[c] >= GF::Traits::dimRange)
53 DUNE_THROW(InvalidStateException, "remap[" << c << "] = "
54 << remap[c] << " >= GF::Traits::dimRange = "
55 << GF::Traits::dimRange);
56 }
57 public:
59 SelectComponentGridFunctionAdapter(GF& gf_, std::size_t first) :
60 gf(gf_)
61 {
62 for(std::size_t c = 0; c < dimR; ++c)
63 remap[c] = first+c;
64 checkRemap();
65 }
66
69 ( GF& gf_, const std::vector<std::size_t> remap_) :
70 gf(gf_)
71 {
72 if(remap_.size() != dimR)
73 DUNE_THROW(Exception, "Got an index map of size "
74 << remap_.size() << " but size " << dimR << " was "
75 "expected.");
76 std::copy(remap_.begin(), remap_.end(), remap);
77 checkRemap();
78 }
79
80 void evaluate(const typename Traits::ElementType &e,
81 const typename Traits::DomainType &x,
82 typename Traits::RangeType &y) const
83 {
84 typename GF::Traits::RangeType y_;
85 gf.evaluate(e,x,y_);
86 for(std::size_t c = 0; c < dimR; ++c)
87 y[c] = y_[remap[c]];
88 }
89
90 const typename Traits::GridViewType& getGridView() const
91 { return gf.getGridView(); }
92
93 template<typename Time>
94 void setTime(Time time) { gf.setTime(time); }
95 };
96
97 } // namspace PDELab
98} // namspace Dune
99
100#endif // DUNE_PDELAB_FUNCTION_SELECTCOMPONENT_HH
For backward compatibility – Do not use this!
Definition adaptivity.hh:28
Base class for all PDELab exceptions.
Definition exceptions.hh:19
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition function.hh:50
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition function.hh:119
GV GridViewType
The type of the grid view the function lives on.
Definition function.hh:116
traits class holding the function signature, same as in local function
Definition function.hh:183
leaf of a function tree
Definition function.hh:302
Select certain component(s) of a gridfunction.
Definition selectcomponent.hh:34
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition selectcomponent.hh:80
const Traits::GridViewType & getGridView() const
Definition selectcomponent.hh:90
SelectComponentGridFunctionAdapter(GF &gf_, const std::vector< std::size_t > remap_)
construct with a full index map
Definition selectcomponent.hh:69
GridFunctionTraits< typename GF::Traits::GridViewType, typename GF::Traits::RangeFieldType, dimR, FieldVector< typename GF::Traits::RangeFieldType, dimR > > Traits
Definition selectcomponent.hh:40
void setTime(Time time)
Definition selectcomponent.hh:94
SelectComponentGridFunctionAdapter(GF &gf_, std::size_t first)
construct with a consecutive range of indices
Definition selectcomponent.hh:59