space_constitution_get.icc
Go to the documentation of this file.
// input space_constitution files:
// shared functions used in space_constitution_get.cc
// and space_constitution_get_old.cc
//
// author: Pierre.Saramito@imag.fr
//
// date: 19 dec 2011
//
// Note:
// - some technical stuff with bison & flex
// - some others for distributed issues:
// * lecture du fichier sur proc=0 -> arbre sur proc=0
// * lecture ecriture arbre sur stringstream sur proc=0
// * broadcast string sur ts procs
// * lecture du stringstream sur ts les proc -> arbre
// * conversion arbre en space_constitution sur ts les procs
//
//
#include <sstream> // flex include it, but in namespace rheolef
#include <cstring>
#include "rheolef/space.h"
#include "rheolef/basis_get.h"
namespace rheolef {
// ================================================================================
// part 0 : symbol table
// ================================================================================
static std::vector<std::string> symbol_table;
static const std::string& symbol (size_t i) { return symbol_table[i]; }
static size_t insert (const std::string& str) {
size_t i = symbol_table.size();
symbol_table.push_back (str);
return i;
}
// ================================================================================
// part 1 : temporary data structure: tree
// ================================================================================
struct basis_geo_t {
basis_geo_t (std::string b="", std::string g="")
: basis(b), geo(g) {}
std::string basis, geo;
};
struct tree_type {
// data:
bool is_hier;
basis_geo_t basis_geo;
std::list<tree_type> hier;
std::string spec;
// allocators:
tree_type(const std::string& basis, const std::string& geo)
: is_hier(false), basis_geo(basis,geo), hier(), spec("undef") {}
tree_type() : is_hier(true), basis_geo(), hier(), spec("undef") {}
tree_type(const std::string& s, const std::list<tree_type>& h) : is_hier(true), basis_geo(), hier(h), spec(s) {}
};
static
void
tree_dump (const tree_type& x, std::ostream& out, size_t level = 0)
{
if (!x.is_hier) {
out << x.basis_geo.basis;
out << "{" << x.basis_geo.geo << "}";
return;
}
if (x.spec != "mixed") { out << x.spec; }
if (x.spec != "mixed" || level != 0) { out << "("; }
std::list<tree_type>::const_iterator iter = x.hier.begin(), last = x.hier.end();
while (iter != last) {
tree_dump (*iter, out, level+1);
++iter;
if (iter != last) { out << "*"; }
}
if (x.spec != "mixed" || level != 0) { out << ")"; }
}
typedef std::list<tree_type> list_type;
static tree_type* result_ptr;
static family_index_option_type _current_fio;
// ================================================================================
// part 2 : parser call
// ================================================================================
typedef int (*parse_type)(void);
template<class Lexer>
static
void
space_constitution_get_pass_1_2 (
idiststream& ids,
parse_type parse,
Lexer& input,
size_t& line_no,
size_t& n_error)
{
// --------------------------------------------
// 1) read from file on io_proc into a string
// --------------------------------------------
typedef distributor::size_type size_type;
std::istream& is = ids.is();
communicator comm = ids.comm();
size_type io_proc = odiststream::io_proc();
size_type my_proc = comm.rank();
std::string str;
if (my_proc == io_proc) {
std::getline (ids.is(), str);
}
// then broadcast the string
#ifdef _RHEOLEF_HAVE_MPI
mpi::broadcast (mpi::communicator(), str, io_proc);
#endif // _RHEOLEF_HAVE_MPI
// ------------------------------------------------------------------------------------
// 2) parse from string on all procs and re-build result_ptr available on all procs
// ------------------------------------------------------------------------------------
std::istringstream istrstr;
istrstr.str (str);
input.yyrestart(istrstr);
symbol_table.clear();
line_no = 1;
n_error = 0;
if (parse() != 0 || n_error != 0) {
is.setstate (std::ios::badbit);
delete_macro (result_ptr); result_ptr = 0;
error_macro ("internal error in space_constitution io (pass 2)");
}
symbol_table.clear();
// then result_ptr is available on all procs
}
// ================================================================================
// part 2 : space_constitution allocator from tree_type
// ================================================================================
template<class T, class M>
static
space_constitution<T,M>
build_from_tree (const tree_type& x) {
if (! x.is_hier) {
geo_basic<T,M> omega (x.basis_geo.geo);
basis_option sopt;
std::string approx = x.basis_geo.basis + sopt.stamp();
return space_constitution<T,M>(omega, approx);
}
if (x.spec == "vector" || x.spec == "tensor") {
assert_macro (x.hier.size() == 1, "unexpected tree");
const tree_type& subtree = *(x.hier.begin());
assert_macro (! subtree.is_hier, "unexpected tree");
geo_basic<T,M> omega (subtree.basis_geo.geo);
basis_option sopt;
std::string approx = subtree.basis_geo.basis + sopt.stamp();
space_constitution<T,M> basis (omega, approx);
space_constitution<T,M> constit;
constit.set_hierarchy(true);
size_t d = omega.dimension();
space_constant::valued_type valued_tag = space_constant::valued_tag(x.spec);
size_t n_comp = space_constant::n_component (valued_tag, d, omega.coordinate_system());
constit.get_hierarchy().resize (n_comp);
for (size_t i_comp = 0; i_comp < n_comp; i_comp++) {
constit.get_hierarchy().operator[] (i_comp) = basis;
}
constit.set_valued_tag (valued_tag);
constit.data().initialize();
return constit;
}
space_constitution<T,M> constit;
constit.set_hierarchy(true);
size_t n_comp = x.hier.size();
constit.get_hierarchy().resize(n_comp);
std::list<tree_type>::const_iterator iter = x.hier.begin();
for (size_t i_comp = 0; i_comp < n_comp; i_comp++, ++iter) {
const tree_type& xi = *iter;
constit.get_hierarchy().operator[] (i_comp) = build_from_tree<T,M> (xi); // recursive call
}
constit.data().initialize();
return constit;
}
} // namespace rheolef
rheolef::tree_type::tree_type
tree_type(const std::string &basis, const std::string &geo)
Definition: space_constitution_get.icc:74
rheolef::_current_fio
static family_index_option_type _current_fio
Definition: basis_get.cc:50
rheolef::io::out
@ out
Definition: rheostream.h:167
rheolef::tree_type::spec
std::string spec
Definition: space_constitution_get.icc:72
rheolef::tree_type::tree_type
tree_type()
Definition: space_constitution_get.icc:76
rheolef::space_constant::n_component
size_type n_component(valued_type valued_tag, size_type d, coordinate_type sys_coord)
Definition: space_constant.cc:136
mkgeo_contraction.h
h
Definition: mkgeo_contraction.sh:179
rheolef::basis
basis_basic< Float > basis
Definition: basis.h:644
rheolef::result_ptr
static tree_type * result_ptr
Definition: space_constitution_get.icc:100
rheolef::valued_tag
space_constant::valued_type valued_tag() const
Definition: field_expr_recursive.h:579
rheolef::tree_type
Definition: space_constitution_get.icc:67
rheolef::space_constant::valued_tag
valued_type valued_tag(const std::string &name)
Definition: space_constant.cc:50
rheolef::space_constant::valued_type
valued_type
Definition: space_constant.h:135
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::parse_type
int(* parse_type)(void)
Definition: space_constitution_get.icc:107
rheolef::basis_geo_t::geo
std::string geo
Definition: space_constitution_get.icc:64
rheolef::basis_geo_t
Definition: space_constitution_get.icc:61
rheolef::odiststream::io_proc
static size_type io_proc()
Definition: diststream.cc:78
basis
see the basis page for the full documentation
assert_macro
#define assert_macro(ok_condition, message)
Definition: dis_macros.h:113
rheolef::list_type
std::list< tree_type > list_type
Definition: space_constitution_get.icc:98
rheolef::basis_geo_t::basis_geo_t
basis_geo_t(std::string b="", std::string g="")
Definition: space_constitution_get.icc:62
rheolef::tree_type::hier
std::list< tree_type > hier
Definition: space_constitution_get.icc:71
rheolef::tree_type::is_hier
bool is_hier
Definition: space_constitution_get.icc:69
rheolef::basis_geo_t::basis
std::string basis
Definition: space_constitution_get.icc:64
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
error_macro
#define error_macro(message)
Definition: dis_macros.h:49
mkgeo_ball.d
d
Definition: mkgeo_ball.sh:154
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::tree_type::tree_type
tree_type(const std::string &s, const std::list< tree_type > &h)
Definition: space_constitution_get.icc:77
rheolef::symbol_table
static std::vector< std::string > symbol_table
Definition: basis_get.cc:90
g
Definition: cavity_dg.h:25
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::tree_type::basis_geo
basis_geo_t basis_geo
Definition: space_constitution_get.icc:70
rheolef::distributor::size_type
std::allocator< int >::size_type size_type
Definition: distributor.h:67
geo
see the geo page for the full documentation