rheolef  6.5
adapt_bamg.cc
Go to the documentation of this file.
1 #include "rheolef/adapt.h"
2 #include "rheolef/form.h"
3 #include "rheolef/field_component.h"
4 #include "rheolef/field_expr_ops.h"
5 #include "rheolef/rheostream.h"
6 
7 namespace rheolef {
8 
9 template<class T, class M>
10 field_basic<T,M>
12  const field_basic<T,M>& uh0,
13  const adapt_option_type& opts);
14 
15 template<class T, class M>
16 field_basic<T,M>
17 proj (const field_basic<T,M>& uh, const std::string& approx = "P1");
18 
19 template<class T, class M>
20 geo_basic<T,M>
22  const field_basic<T,M>& uh,
23  const adapt_option_type& opts)
24 {
25  using namespace std;
26  typedef typename geo_basic<T,M>::size_type size_type;
27  bool do_verbose = iorheo::getverbose(clog);
28  bool do_clean = iorheo::getclean(clog);
29  string command;
30  // 1a) sortie du maillage : nom-<i>.geo
31  const geo_basic<T,M>& omega = uh.get_geo();
32  size_type i = omega.serial_number();
33  string i_name = omega.name();
34  string geo_name = i_name + ".geo";
35  odiststream out;
36  if (! dis_file_exists(geo_name) &&
37  ! dis_file_exists(geo_name + ".gz")) {
38  out.open (geo_name);
39  out << omega;
40  check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
41  out.close();
42  }
43  // 1b) conversion geo : nom-<i>.bamg
44  string bamg_name = i_name + ".bamg";
45  // 2a) sortie du critere : nom-crit-<i>.field
46  string crit_name = i_name + "-crit.field";
47  out.open (crit_name, "field");
48  out << proj (uh);
49  check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
50  out.close();
51  // 2b) conversion field : nom-crit-<i>.bb
52  string bb_name = i_name + "-crit.bb";
53  command = "field -noverbose -bamg-bb " + crit_name + " > " + bb_name;
54  if (do_verbose) clog << "! " << command << endl;
55  check_macro (dis_system (command) == 0, "adapt: unix command failed");
56  // => nom-<i+1>.bamg
57  string bamgcad_file = omega.familyname() + ".bamgcad";
58  check_macro (dis_file_exists(bamgcad_file), "adapt: missing \""<<bamgcad_file<<"\" file");
59  size_type k = uh.get_space().degree();
60  if (! uh.get_space().get_numbering().is_continuous()) k++; // uh is a grad of a solution
61  Float error = opts.err;
62  if (k > 1) {
63  // when k > 1, decreses the interpolation error level for bamg, as computed when k=1
64  error = pow (error, 2./(k+1));
65  }
66  string options =
67  "-coef " + ftos(opts.hcoef)
68  + " -err " + ftos(error)
69  + " -errg " + ftos(opts.errg)
70  + " -hmin " + ftos(opts.hmin)
71  + " -hmax " + ftos(opts.hmax)
72  + " -ratio " + ftos(opts.ratio)
73  + " -anisomax " + ftos(opts.anisomax)
74  + " -nbv " + itos(opts.n_vertices_max)
75  + " -NbJacobi " + itos(opts.n_smooth_metric)
76  + " -CutOff " + ftos(opts.cutoff);
77  if (opts.splitpbedge) {
78  options += " -splitpbedge ";
79  }
80  if (opts.thetaquad != numeric_limits<Float>::max()) {
81  options += " -thetaquad " + ftos(opts.thetaquad);
82  }
83  options += " " + opts.additional;
84  string i1_name = omega.familyname() + "-" + itos(i+1);
85  command = "bamg "
86  + options
87  + " -b " + bamg_name
88  + " -Mbb " + bb_name
89  + " -o " + i1_name + ".bamg";
90  if (do_verbose) clog << "! " << command << endl;
91  check_macro (dis_system (command) == 0, "adapt: command failed");
92  // 4) conversion : nom-crit-<i>.bamg
93  string dmn_name = omega.familyname() + ".dmn";
94  command = "bamg2geo -" + omega.coordinate_system_name()
95  + " " + dmn_name + " " + i1_name + ".bamg | gzip -9 > "
96  + i1_name + ".geo.gz";
97  if (do_verbose) clog << "! " << command << endl;
98  check_macro (dis_system (command) == 0, "adapt: command failed");
99  // 5) chargement nom-<i+1>.geo
100  idiststream in (i1_name, "geo");
101  geo_basic<T,M> new_omega;
102  in >> new_omega;
103  new_omega.set_name (omega.familyname());
104  new_omega.set_serial_number (i+1);
105  return new_omega;
106 }
107 #define _RHEOLEF_instanciation(T,M) \
108 template geo_basic<T,M> adapt_bamg (const field_basic<T,M>&, const adapt_option_type&);
109 
110 _RHEOLEF_instanciation(Float,sequential)
111 #ifdef _RHEOLEF_HAVE_MPI
113 #endif // _RHEOLEF_HAVE_MPI
114 
115 } // namespace rheolef
116