2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
6
/// Rheolef is free software; you can redistribute it and/or modify
7
/// it under the terms of the GNU General Public License as published by
8
/// the Free Software Foundation; either version 2 of the License, or
9
/// (at your option) any later version.
11
/// Rheolef is distributed in the hope that it will be useful,
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
/// GNU General Public License for more details.
16
/// You should have received a copy of the GNU General Public License
17
/// along with Rheolef; if not, write to the Free Software
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/// =========================================================================
21
#include "rheolef/adapt.h"
22
#include "rheolef/form.h"
23
#include "rheolef/field_component.h"
24
#include "rheolef/field_expr_ops.h"
25
#include "rheolef/rheostream.h"
30
template<class T, class M>
33
const field_basic<T,M>& uh0,
34
const adapt_option_type& opts);
36
template<class T, class M>
38
proj (const field_basic<T,M>& uh, const std::string& approx = "P1");
40
// -----------------------------------------
42
// -----------------------------------------
43
template<class T, class M>
46
const field_basic<T,M>& uh,
47
const adapt_option_type& opts)
50
typedef typename geo_basic<T,M>::size_type size_type;
51
bool do_verbose = iorheo::getverbose(clog);
52
bool do_clean = iorheo::getclean(clog);
54
// -----------------------------------------
55
// 1a) sortie du maillage : nom-<i>.geo
56
// -----------------------------------------
57
const geo_basic<T,M>& omega = uh.get_geo();
58
size_type i = omega.serial_number();
59
string i_name = omega.name();
60
string geo_name = i_name + ".geo";
62
if (! dis_file_exists(geo_name) &&
63
! dis_file_exists(geo_name + ".gz")) {
66
check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
69
// ----------------------------------------
70
// 1b) conversion geo : nom-<i>.bamg
71
// ----------------------------------------
72
string bamg_name = i_name + ".bamg";
74
command = "geo -noverbose -bamg " + geo_name + " > " + bamg_name;
75
if (do_verbose) clog << "! " << command << endl;
76
check_macro (dis_system (command) == 0, "adapt: unix command failed");
78
// -----------------------------------------
79
// 2a) sortie du critere : nom-crit-<i>.field
80
// -----------------------------------------
81
string crit_name = i_name + "-crit.field";
82
out.open (crit_name, "field");
84
check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
86
// --------------------------------------------
87
// 2b) conversion field : nom-crit-<i>.bb
88
// --------------------------------------------
89
string bb_name = i_name + "-crit.bb";
90
command = "field -noverbose -bamg-bb " + crit_name + " > " + bb_name;
91
if (do_verbose) clog << "! " << command << endl;
92
check_macro (dis_system (command) == 0, "adapt: unix command failed");
93
// ----------------------------------------
94
// 3) run bamg in adapt mode:
96
// ----------------------------------------
97
string bamgcad_file = omega.familyname() + ".bamgcad";
98
check_macro (dis_file_exists(bamgcad_file), "adapt: missing \""<<bamgcad_file<<"\" file");
99
size_type k = uh.get_space().degree();
100
if (! uh.get_space().get_numbering().is_continuous()) k++; // uh is a grad of a solution
101
Float error = opts.err;
103
// when k > 1, decreses the interpolation error level for bamg, as computed when k=1
104
error = pow (error, 2./(k+1));
107
"-coef " + ftos(opts.hcoef)
108
+ " -err " + ftos(error)
109
+ " -errg " + ftos(opts.errg)
110
+ " -hmin " + ftos(opts.hmin)
111
+ " -hmax " + ftos(opts.hmax)
112
+ " -ratio " + ftos(opts.ratio)
113
+ " -anisomax " + ftos(opts.anisomax)
114
+ " -nbv " + itos(opts.n_vertices_max)
115
+ " -NbJacobi " + itos(opts.n_smooth_metric)
116
+ " -CutOff " + ftos(opts.cutoff);
117
if (opts.splitpbedge) {
118
options += " -splitpbedge ";
120
if (opts.thetaquad != numeric_limits<Float>::max()) {
121
options += " -thetaquad " + ftos(opts.thetaquad);
123
options += " " + opts.additional;
124
string i1_name = omega.familyname() + "-" + itos(i+1);
129
+ " -o " + i1_name + ".bamg";
130
if (do_verbose) clog << "! " << command << endl;
131
check_macro (dis_system (command) == 0, "adapt: command failed");
132
// ----------------------------------------
133
// 4) conversion : nom-crit-<i>.bamg
134
// ----------------------------------------
135
string dmn_name = omega.familyname() + ".dmn";
136
command = "bamg2geo " + dmn_name + " " + i1_name + ".bamg | gzip -9 > " + i1_name + ".geo.gz";
137
if (do_verbose) clog << "! " << command << endl;
138
check_macro (dis_system (command) == 0, "adapt: command failed");
139
// ----------------------------------------
140
// 5) chargement nom-<i+1>.geo
141
// ----------------------------------------
142
idiststream in (i1_name, "geo");
143
geo_basic<T,M> new_omega;
145
new_omega.set_name (omega.familyname());
146
new_omega.set_serial_number (i+1);
149
// ----------------------------------------------------------------------------
150
// instanciation in library
151
// ----------------------------------------------------------------------------
152
#define _RHEOLEF_instanciation(T,M) \
153
template geo_basic<T,M> adapt_bamg (const field_basic<T,M>&, const adapt_option_type&);
155
_RHEOLEF_instanciation(Float,sequential)
156
#ifdef _RHEOLEF_HAVE_MPI
157
_RHEOLEF_instanciation(Float,distributed)
158
#endif // _RHEOLEF_HAVE_MPI
160
} // namespace rheolef