Plugins
Loading...
Searching...
No Matches
val_surf_proj_impl.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
3 * SPDX-License-Identifier: EUPL-1.2
4 * SPDX-FileContributor: Dmitry Logashenko
5 * SPDX-FileContributor: Goethe Universität Frankfurt
6 * SPDX-FileType: SOURCE
7 *
8 * This file is part of d3f++.
9 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
10 */
11
12
13/*
14 * Projection of values of a given grid function from a given z-plane to a given subset.
15 */
16#include <limits>
17
20#ifdef UG_PARALLEL
22#endif
23
24namespace ug{
25namespace d3f{
26
30template <typename TGridFunction>
32(
33 SmartPtr<gf_type> spLSF,
34 const char * cmp,
35 number z_coord,
36 const char * subsetNames
37)
38: m_spLSF (spLSF), m_z_coord (z_coord), m_glob_userdata (spLSF, cmp), m_default_value (0)
39{
40 m_SsGrp.set_subset_handler (spLSF->domain()->subset_handler ());
41 m_SsGrp.add (TokenizeString (subsetNames));
42 spLSF->domain()->grid()->attach_to_vertices_dv (m_a_vrt_num, (size_t) -1);
43}
44
48template <typename TGridFunction>
50{
51 typedef typename gf_type::template traits<Vertex>::const_iterator vrt_iter_t;
52
53// initialize the attachment
54 num_aa_type aa_vrt_num (* m_spLSF->domain()->grid (), m_a_vrt_num);
55 size_t vrt_num = 0;
56 for (size_t i = 0; i < m_SsGrp.size (); i++)
57 {
58 int si = m_SsGrp[i];
59 for (vrt_iter_t iter = m_spLSF->template begin<Vertex> (si);
60 iter != m_spLSF->template end<Vertex> (si); ++iter)
61 aa_vrt_num [*iter] = vrt_num++;
62 }
63
64# ifndef UG_PARALLEL
65
66// initialize the values
67 m_vrt_val.resize (vrt_num);
68 const pos_acc_type aa_pos = m_spLSF->domain()->position_accessor ();
69 for (size_t i = 0; i < m_SsGrp.size (); i++)
70 {
71 int si = m_SsGrp[i];
72 for (vrt_iter_t iter = m_spLSF->template begin<Vertex> (si);
73 iter != m_spLSF->template end<Vertex> (si); ++iter)
74 {
75 Vertex * vrt = * iter;
76 const MathVector<dim> & pos = aa_pos [vrt];
77 MathVector<dim> the_pos;
78 for (size_t k = 0; k < dim - 1; k++) the_pos[k] = pos[k];
79 the_pos[dim-1] = m_z_coord;
80 if (! m_glob_userdata.evaluate (m_vrt_val [aa_vrt_num [vrt]], the_pos))
81 m_vrt_val [aa_vrt_num [vrt]] = m_default_value;
82 }
83 }
84
85# else // i.e. ifdef UG_PARALLEL
86
87 {
89
90 // get the points where the values must be computed
91 std::vector<MathVector<dim> > proc_pos (vrt_num);
92 pos_acc_type aa_pos = m_spLSF->domain()->position_accessor ();
93 for (size_t i = 0; i < m_SsGrp.size (); i++)
94 {
95 int si = m_SsGrp[i];
96 for (vrt_iter_t iter = m_spLSF->template begin<Vertex> (si);
97 iter != m_spLSF->template end<Vertex> (si); ++iter)
98 {
99 Vertex * vrt = * iter;
100 const MathVector<dim> & pos = aa_pos [vrt];
101 MathVector<dim> & the_pos = proc_pos [aa_vrt_num [vrt]];
102 for (size_t k = 0; k < dim - 1; k++) the_pos[k] = pos[k];
103 the_pos[dim-1] = m_z_coord;
104 }
105 }
106 std::vector<MathVector<dim> > all_pos;
107 std::vector<int> offset;
108 proc_comm.allgatherv (all_pos, proc_pos, NULL, &offset);
109
110 // compute the values at all the positions
111 std::vector<number> tmp_vrt_val (all_pos.size ());
112 for (size_t j = 0; j < tmp_vrt_val.size (); j++)
113 if (! m_glob_userdata.evaluate (tmp_vrt_val [j], all_pos[j]))
114 tmp_vrt_val [j] = - std::numeric_limits<number>::max (); // the position is not covered by the free surface in this process
115
116 // compose the common values
117 std::vector<number> all_vrt_val (tmp_vrt_val.size ());
118 proc_comm.allreduce (tmp_vrt_val, all_vrt_val, PCL_RO_MAX);
119
120 // extract the values from the common array
121 m_vrt_val.resize (vrt_num);
122 int my_offset = offset [proc_comm.get_local_proc_id ()];
123 for (size_t j = 0; j < vrt_num; j++)
124 {
125 number val = all_vrt_val [my_offset + j];
126 if (val == - std::numeric_limits<number>::max ()) // i.e. is not set in any process
127 m_vrt_val [j] = m_default_value;
128 else
129 m_vrt_val [j] = all_vrt_val [my_offset + j];
130 }
131 }
132
133# endif // UG_PARALLEL
134}
135
139template <typename TGridFunction>
140template <int refDim>
142(
143 number vValue[],
144 const MathVector<dim> vGlobIP[],
145 number time,
146 int si,
147 GridObject* grid_obj,
148 const MathVector<dim> vCornerCoords[],
149 const MathVector<refDim> vLocIP[],
150 const size_t nip,
151 LocalVector* u,
152 bool bDeriv,
153 int s,
154 std::vector<std::vector<number> > vvvDeriv[],
155 const MathMatrix<refDim, dim>* vJT
156)
157{
158 typedef typename gf_type::template dim_traits<refDim>::grid_base_object elem_type;
159
160// May be used only on the specified subsets!
161 if (! m_SsGrp.contains (si))
162 UG_THROW ("ValSurfProjData: Attempt to get the value for a subset that has not been specified.");
163
164// Interpolate the values
165
166 const ReferenceObjectID roid = grid_obj->reference_object_id ();
167 const elem_type * elem = dynamic_cast<elem_type *> (grid_obj);
168
169 const LocalShapeFunctionSet<refDim> & rTrialSpace =
170 LocalFiniteElementProvider::get<refDim> (roid, LFEID (LFEID::LAGRANGE, refDim, 1));
171
172 num_aa_type aa_vrt_num (* m_spLSF->domain()->grid (), m_a_vrt_num);
173
174 std::vector<number> shape;
175
176 for (size_t ip = 0; ip < nip; ip++)
177 {
178 // evaluate at shapes at ip
179 rTrialSpace.shapes (shape, vLocIP [ip]);
180 UG_ASSERT (shape.size () == elem->num_vertices (), "ValSurfProjData: Hanging nodes are not supported!");
181
182 // compute solution at integration point
183 vValue [ip] = 0;
184 for(size_t sh = 0; sh < shape.size (); sh++)
185 {
186 const Vertex * vrt = elem->vertex (sh);
187 size_t vrt_no = aa_vrt_num [vrt];
188 if (vrt_no == (size_t) -1)
189 UG_THROW ("ValSurfProjData: The object is not properly initialized.");
190 vValue [ip] += m_vrt_val [vrt_no] * shape [sh];
191 }
192 }
193
194 if (bDeriv)
195 {
196 for (size_t ip = 0; ip < nip; ip++)
197 {
198 rTrialSpace.shapes(shape, vLocIP [ip]);
199 for (size_t sh = 0; sh < shape.size(); sh++) vvvDeriv [ip] [0] [sh] = shape [sh];
200 }
201 }
202}
203
204} // end namespace d3f
205} // end namespace ug
206
207/* End of File */
parameterString s
Definition Biogas.lua:2
size_t allreduce(const size_t &t, pcl::ReduceOperation op) const
void allgatherv(const void *sendBuf, int sendCount, DataType sendType, void *recBuf, int *recCounts, int *displs, DataType recType) const
int get_local_proc_id(int globalProcID=pcl::ProcRank()) const
virtual ReferenceObjectID reference_object_id() const=0
virtual void shapes(std::vector< std::vector< shape_type > > &vvShape, const std::vector< MathVector< dim > > &vLocPos) const=0
void add(const char *name)
void set_subset_handler(ConstSmartPtr< ISubsetHandler > sh)
void eval_and_deriv(number vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, bool bDeriv, int s, std::vector< std::vector< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL)
Performs the main computations:
Definition val_surf_proj_impl.h:142
num_a_type m_a_vrt_num
attachment keeping a numbering of the vertices in the subsets
Definition val_surf_proj.h:135
SubsetGroup m_SsGrp
(low-dimensional) subsets to compute the coordinates over
Definition val_surf_proj.h:125
ValSurfProjData(SmartPtr< gf_type > spLSF, const char *cmp, number z_coord, const char *subsets)
Constructor.
Definition val_surf_proj_impl.h:32
void reinit()
Initializer (should be called before every use)
Definition val_surf_proj_impl.h:49
domain_type::position_accessor_type pos_acc_type
position attachment accessor type
Definition val_surf_proj.h:63
#define PCL_RO_MAX
vector< string > TokenizeString(const char *str, const char delimiter=',')
#define UG_ASSERT(expr, msg)
#define UG_THROW(msg)
double number
ReferenceObjectID