DUNE PDELab (git)

selectcomponent.hh
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
11
12#include <dune/pdelab/common/function.hh>
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,
40 > Traits;
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
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
Base class for all PDELab exceptions.
Definition: exceptions.hh:19
leaf of a function tree
Definition: function.hh:302
Select certain component(s) of a gridfunction.
Definition: selectcomponent.hh:34
SelectComponentGridFunctionAdapter(GF &gf_, const std::vector< std::size_t > remap_)
construct with a full index map
Definition: selectcomponent.hh:69
SelectComponentGridFunctionAdapter(GF &gf_, std::size_t first)
construct with a consecutive range of indices
Definition: selectcomponent.hh:59
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:50
traits class holding the function signature, same as in local function
Definition: function.hh:183
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)