1515
1616using namespace mfem ;
1717
18+ using profile_t = std::function<real_t (const Vector&,const Vector&)>;
19+
1820void L2Reconstruction (const GridFunction& src, GridFunction& dst);
21+ std::vector<std::pair<std::string, profile_t >> GetFieldProfiles ();
1922
2023int main (int argc, char * argv[])
2124{
@@ -38,34 +41,7 @@ int main(int argc, char* argv[])
3841 int visport = 19916 ;
3942
4043 // example field profiles
41- using profile_t = std::function<real_t (const Vector&,const Vector&)>;
42- std::vector<std::pair<std::string, profile_t >> field_profiles;
43- // plane profile
44- field_profiles.push_back (std::make_pair (
45- " 1 + kx x + ky y" ,
46- [](const Vector &x, const Vector &k)
47- {
48- return 1.0 + x*k;
49- }));
50- // sinusoidal profile
51- field_profiles.push_back (std::make_pair (
52- " sin(2pi kx x) sin(2pi ky y)" ,
53- [](const Vector &x, const Vector &k)
54- {
55- real_t result = 1.0 ;
56- for (int i=0 ; i < x.Size (); i++) result *= std::sin (2.0 *M_PI*k (i)*x (i));
57- return result;
58- }));
59- // exponential-sinusoidal profile
60- field_profiles.push_back (std::make_pair (
61- " exp(r) cos(kx x) sin(ky y)" ,
62- [](const Vector &x, const Vector &k)
63- {
64- real_t result = 1.0 ;
65- for (int i=0 ; i < x.Size (); i++)
66- result *= std::exp (x.Norml2 ()) * std::sin (2.0 *M_PI*k (i)*x (i));
67- return result;
68- }));
44+ std::vector<std::pair<std::string, profile_t >> field_profiles = GetFieldProfiles ();
6945 // create CLI help string for profiles
7046 std::string field_profiles_help = " Profile of field to be reconstructed:" ;
7147 for (int i=0 ; i < field_profiles.size (); i++)
@@ -273,6 +249,38 @@ void SaturateNeighborhood(NCMesh& mesh, const int element_idx,
273249 neighbors.Unique ();
274250}
275251
252+ std::vector<std::pair<std::string, profile_t >> GetFieldProfiles ()
253+ {
254+ std::vector<std::pair<std::string, profile_t >> field_profiles;
255+ // plane profile
256+ field_profiles.push_back (std::make_pair (
257+ " 1 + kx x + ky y" ,
258+ [](const Vector &x, const Vector &k)
259+ {
260+ return 1.0 + x*k;
261+ }));
262+ // sinusoidal profile
263+ field_profiles.push_back (std::make_pair (
264+ " sin(2pi kx x) sin(2pi ky y)" ,
265+ [](const Vector &x, const Vector &k)
266+ {
267+ real_t result = 1.0 ;
268+ for (int i=0 ; i < x.Size (); i++) result *= std::sin (2.0 *M_PI*k (i)*x (i));
269+ return result;
270+ }));
271+ // exponential-sinusoidal profile
272+ field_profiles.push_back (std::make_pair (
273+ " exp(r) cos(kx x) sin(ky y)" ,
274+ [](const Vector &x, const Vector &k)
275+ {
276+ real_t result = 1.0 ;
277+ for (int i=0 ; i < x.Size (); i++)
278+ result *= std::exp (x.Norml2 ()) * std::sin (2.0 *M_PI*k (i)*x (i));
279+ return result;
280+ }));
281+ return field_profiles;
282+ }
283+
276284void L2Reconstruction (const GridFunction& src, GridFunction& dst)
277285{
278286 const real_t RTOL = 1.0e-5 ;
0 commit comments