~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to nfem/plib/adapt_bamg.cc

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///
 
2
/// This file is part of Rheolef.
 
3
///
 
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
5
///
 
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.
 
10
///
 
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.
 
15
///
 
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
 
19
/// 
 
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"
 
26
 
 
27
namespace rheolef {
 
28
 
 
29
// extern in adapt.cc
 
30
template<class T, class M>
 
31
field_basic<T,M>
 
32
hessian_criterion (
 
33
    const field_basic<T,M>&  uh0,
 
34
    const adapt_option_type& opts);
 
35
 
 
36
template<class T, class M>
 
37
field_basic<T,M>
 
38
proj (const field_basic<T,M>& uh, const std::string& approx = "P1");
 
39
 
 
40
// -----------------------------------------
 
41
// adapt
 
42
// -----------------------------------------
 
43
template<class T, class M>
 
44
geo_basic<T,M>
 
45
adapt_bamg (
 
46
    const field_basic<T,M>&  uh,
 
47
    const adapt_option_type& opts)
 
48
{
 
49
  using namespace std;
 
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);
 
53
  string command;
 
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";
 
61
  odiststream out;
 
62
  if (! dis_file_exists(geo_name) &&
 
63
      ! dis_file_exists(geo_name + ".gz")) {
 
64
    out.open (geo_name);
 
65
    out << omega;
 
66
    check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
 
67
    out.close();
 
68
  }
 
69
  // ----------------------------------------
 
70
  // 1b) conversion geo : nom-<i>.bamg
 
71
  // ----------------------------------------
 
72
  string bamg_name = i_name + ".bamg";
 
73
#ifdef TO_CLEAN
 
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");
 
77
#endif // TO_CLEAN
 
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");
 
83
  out << proj (uh);
 
84
  check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
 
85
  out.close();
 
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:
 
95
  //     => nom-<i+1>.bamg
 
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;
 
102
  if (k > 1) {
 
103
    // when k > 1, decreses the interpolation error level for bamg, as computed when k=1
 
104
    error = pow (error, 2./(k+1));
 
105
  }
 
106
  string options =
 
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 ";
 
119
  }
 
120
  if (opts.thetaquad != numeric_limits<Float>::max()) {
 
121
    options += " -thetaquad " + ftos(opts.thetaquad);
 
122
  }
 
123
  options += " " + opts.additional;
 
124
  string i1_name = omega.familyname() + "-" + itos(i+1);
 
125
  command = "bamg "
 
126
    + options
 
127
    + " -b " + bamg_name
 
128
    + " -Mbb " + bb_name
 
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;
 
144
  in >> new_omega;
 
145
  new_omega.set_name (omega.familyname());
 
146
  new_omega.set_serial_number (i+1);
 
147
  return new_omega;
 
148
}
 
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&);
 
154
 
 
155
_RHEOLEF_instanciation(Float,sequential)
 
156
#ifdef _RHEOLEF_HAVE_MPI
 
157
_RHEOLEF_instanciation(Float,distributed)
 
158
#endif // _RHEOLEF_HAVE_MPI
 
159
 
 
160
} // namespace rheolef