Plugins
Loading...
Searching...
No Matches
smile_rescale_impl.hpp
Go to the documentation of this file.
1
12#ifdef UG_PARALLEL
14#endif
15
16namespace ug {
17namespace smile {
18
20template <typename TDomain, typename TAlgebra>
21template <typename TElem>
23(
24 int si,
25 gf_type & gf,
26 aa_factor_type & aa_factor
27)
28{
29 typedef typename gf_type::template traits<TElem>::const_iterator iterator;
31 typedef FV1Geometry<TElem, WDim> FVGeom_type;
32
33 const size_t n_co = ref_elem_type::numCorners;
34 const size_t n_scv = FVGeom_type::numSCV; // actually, we assume n_scv == n_co
35
36 LocalIndices loc_ind;
37 LocalVector loc_vec;
38
39// get position accessor
40 domain_type & dom = * gf.domain ();
41 position_accessor_type & aaPos = dom.position_accessor ();
42
43 FVGeom_type & geo = GeomProvider<FVGeom_type>::get();
44
45 position_type e_corners [n_co];
46 Vertex * e_vrt [n_co];
47
48// loop the elements in the subset
49 iterator end_e_iter = gf.template end<TElem>(si);
50 for (iterator e_iter = gf.template begin<TElem>(si); e_iter != end_e_iter; ++e_iter)
51 {
52 TElem * e = *e_iter;
53
54 // get vertices and extract corner coordinates
55 for (size_t i = 0; i < n_co; i++)
56 e_corners[i] = aaPos [e_vrt[i] = e->vertex (i)];
57
58 // compute the FV geometry
59 try
60 {
61 geo.update (e, e_corners, dom.subset_handler().get ());
62 }
63 UG_CATCH_THROW("SmartRescaler: Cannot update the Finite Volume Geometry for an element.");
64
65 // get the local vector
66 gf.indices (e, loc_ind);
67 loc_vec.resize (loc_ind);
68 GetLocalVector (loc_vec, gf);
69
70 // get the values of the factor
71 number factor_values [n_scv];
72 (* m_spFactor) (factor_values, e_corners, 0, si, e,
73 geo.scv_global_ips (), geo.scv_local_ips (), n_scv, &loc_vec);
74
75 // evaluate the factor in at the corners
76 for (size_t i = 0; i < n_scv; i++)
77 {
78 const typename FVGeom_type::SCV & scv = geo.scv (i);
79 aa_factor [e_vrt [scv.node_id()]] += factor_values[i] * scv.volume ();
80 }
81 }
82}
83
85template <typename TDomain, typename TAlgebra>
87(
88 gf_type & gf,
89 a_factor_type & a_factor
90)
91{
92 domain_type & dom = * gf.domain ();
93 grid_type & g = * dom.grid ();
94
95 if (m_spFactor.invalid ())
96 UG_THROW ("SmartRescaler: No factor specified!");
97
98 m_spFactor->set_function_pattern (gf.function_pattern ());
99
100 aa_factor_type aa_factor (g, a_factor);
101 SetAttachmentValues (aa_factor, g.template begin<Vertex> (), g.template end<Vertex> (), 0);
102
103// The full-dim. grid element types for this dimension:
104 typedef typename domain_traits<WDim>::DimElemList ElemList;
105 subset_handler_type & ssh = * dom.subset_handler();
106 for (int si = 0; si < ssh.num_subsets (); si++)
107 boost::mpl::for_each<ElemList> (GetScalingFactors (this, si, gf, aa_factor));
108
109# ifdef UG_PARALLEL
110 AttachmentAllReduce<Vertex> (g, a_factor, PCL_RO_SUM);
111# endif
112}
113
115template <typename TDomain, typename TAlgebra>
117(
119 const char * cmp
120)
121{
122 typedef typename gf_type::template traits<Vertex>::const_iterator iterator;
123
124// get the components
125 size_t fct = gf->fct_id_by_name (cmp);
126
127// create the attachment
128 domain_type & dom = * gf->domain ();
129 grid_type & g = * dom.grid ();
130 a_factor_type a_factor;
131 g.attach_to_vertices (a_factor);
132
133// compute the scaling factors
134 get_scaling_factors (*gf, a_factor);
135 aa_factor_type aa_factor (g, a_factor);
136
137 iterator end_v_iter = gf->template end<Vertex> ();
138 for (iterator v_iter = gf->template begin<Vertex> (); v_iter != end_v_iter; ++v_iter)
139 {
140 Vertex * vrt = *v_iter;
141 number factor = aa_factor [vrt];
142
143 std::vector<DoFIndex> ind (1);
144 gf->inner_dof_indices (vrt, fct, ind);
145 DoFRef(*gf, ind[0]) *= factor; // this '*=' should be the only difference to 'divide'
146 }
147
148 g.detach_from_vertices (a_factor);
149}
150
152template <typename TDomain, typename TAlgebra>
154(
156 const char * cmp
157)
158{
159 typedef typename gf_type::template traits<Vertex>::const_iterator iterator;
160
161// get the components
162 size_t fct = gf->fct_id_by_name (cmp);
163
164// create the attachment
165 domain_type & dom = * gf->domain ();
166 grid_type & g = * dom.grid ();
167 a_factor_type a_factor;
168 g.attach_to_vertices (a_factor);
169
170// compute the scaling factors
171 get_scaling_factors (*gf, a_factor);
172 aa_factor_type aa_factor (g, a_factor);
173
174 iterator end_v_iter = gf->template end<Vertex> ();
175 for (iterator v_iter = gf->template begin<Vertex> (); v_iter != end_v_iter; ++v_iter)
176 {
177 Vertex * vrt = *v_iter;
178 number factor = aa_factor [vrt];
179
180 std::vector<DoFIndex> ind (1);
181 gf->inner_dof_indices (vrt, fct, ind);
182 DoFRef(*gf, ind[0]) /= factor; // this '/=' should be the only difference to 'multiply'
183 }
184
185 g.detach_from_vertices (a_factor);
186}
187
188} // end namespace smile
189} // end namespace ug
190
191/* End of File */
ConstSmartPtr< FunctionPattern > function_pattern() const
static TGeom & get()
void indices(TElem *elem, LocalIndices &ind, bool bHang=false) const
SmartPtr< TDomain > domain()
void resize(const LocalIndices &ind)
void get_scaling_factors(gf_type &gf, a_factor_type &factor)
Compute (sum up) the scaling factors (over the entire grid)
Definition smile_rescale_impl.hpp:87
TDomain domain_type
Type of Domain.
Definition smile_rescale.hpp:33
void get_scaling_factors_for_(int si, gf_type &gf, aa_factor_type &factor)
Compute (sum up) the scaling factors (for one element type)
Definition smile_rescale_impl.hpp:23
void divide(SmartPtr< gf_type > gf, const char *cmps)
Divide the given components of the grid function by the factors.
Definition smile_rescale_impl.hpp:154
domain_type::position_type position_type
Type of the position coordinate vectors.
Definition smile_rescale.hpp:45
TDomain::grid_type grid_type
Type of Grid:
Definition smile_rescale.hpp:36
void multiply(SmartPtr< gf_type > gf, const char *cmps)
Multiplies the given components of the grid function by the factors.
Definition smile_rescale_impl.hpp:117
domain_type::position_accessor_type position_accessor_type
Type of the position accessor.
Definition smile_rescale.hpp:42
domain_type::subset_handler_type subset_handler_type
Type of subset handler.
Definition smile_rescale.hpp:39
void SetAttachmentValues(TAttachmentAccessor &aaVal, TIter elemsBegin, TIter elemsEnd, const TVal &val)
#define PCL_RO_SUM
#define UG_CATCH_THROW(msg)
#define UG_THROW(msg)
double number
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
void GetLocalVector(LocalVector &lvec, const TVector &vec)
Helper class for the computation of the factors.
Definition smile_rescale.hpp:102