9 #include <boost/lexical_cast.hpp>
41 #define CF3_BREAK_LINE(f,x) { if( x+1 % 10) { f << "\n"; } }
49 Writer::Writer(
const std::string&
name )
54 .description(
"True if discontinuous fields are to be plotted as cell-centred fields");
61 std::vector<std::string> extensions;
62 extensions.push_back(
".smurf");
74 nb_nodes = coordinates.
size();
77 if (PE::Comm::instance().size() > 1)
78 path = boost::filesystem::basename(path) +
"_P" +
to_str(PE::Comm::instance().rank()) + boost::filesystem::extension(path);
83 std::vector< std::string > vn;
84 std::vector< std::vector<double> > vv;
85 vn.reserve(dimension+
m_fields.size());
86 vv.reserve(vn.size());
89 for (
Uint d = 0; d < dimension; ++d)
91 std::vector<double> var; var.reserve(nb_nodes);
92 for (
int j=0; j<coordinates.
size(); ++j)
95 var.push_back(coordinates[j][d]);
98 vn.push_back(
"x"+boost::lexical_cast<std::string>(d));
99 CFdebug <<
"smurf: adding coordinate \"" << vn.back() <<
"\"" <<
CFendl;
104 const Field& field = *field_ptr;
109 std::string var_name = field.
var_name(iVar);
110 CFdebug <<
"smurf: adding variable \"" << var_name <<
"\"" <<
CFendl;
112 for (
Uint i=0; i<static_cast<Uint>(var_type); ++i)
117 if ( &field.
dict() == &
m_mesh->geometry_fields() )
119 std::vector<double> var; var.reserve(nb_nodes);
120 for (
Uint n=0;
n<nb_nodes; ++
n)
122 var.push_back(field[
n][var_idx]);
125 vn.push_back(var_name);
134 const Space& field_space = field.
space(elements);
137 std::vector<Real> nodal_data(
used_nodes.size(),0.);
140 const RealMatrix& geometry_local_coords = elements.geometry_space().shape_function().local_coordinates();
142 for (
Uint g=0;
g<interpolation.rows(); ++
g)
144 interpolation.row(
g) = sf.
value(geometry_local_coords.row(
g));
148 for (
Uint e=0;
e<elements.size(); ++
e)
159 field_data[iState] = field[field_index[iState]][var_idx];
163 RealVector geometry_field_data = interpolation*field_data;
166 cf3_assert(geometry_field_data.size()==geom_nodes.size());
168 for (
Uint g=0;
g<geom_nodes.size(); ++
g)
170 const Uint geom_node = geom_nodes[
g];
171 const Uint node_idx = zone_node_idx[geom_node]-1;
173 nodal_data[node_idx] = geometry_field_data[
g];
177 vv.push_back(nodal_data);
178 vv.push_back(var_name);
194 const Space& field_space = field.
space(elements);
199 boost::shared_ptr< ShapeFunction > P0_cell_centred = boost::dynamic_pointer_cast<
ShapeFunction>(
build_component(
"cf3.mesh.LagrangeP0."+
to_str(elements.element_type().shape_name()),
"tmp_shape_func"));
201 for (
Uint e=0;
e<elements.size(); ++
e)
209 field_data[iState] = field[field_index[iState]][var_idx];
213 RealVector local_coords = P0_cell_centred->local_coordinates().
row(0);
219 file << cell_centred_data <<
" ";
227 std::vector<Real> nodal_data(
used_nodes.size(),0.);
228 std::vector<Uint> nodal_data_count(
used_nodes.size(),0u);
231 const RealMatrix& geometry_local_coords = elements.geometry_space().shape_function().local_coordinates();
233 for (
Uint g=0;
g<interpolation.rows(); ++
g)
235 interpolation.row(
g) = sf.
value(geometry_local_coords.row(
g));
238 for (
Uint e=0;
e<elements.size(); ++
e)
245 field_data[iState] = field[field_index[iState]][var_idx];
249 RealVector geometry_field_data = interpolation*field_data;
252 cf3_assert(geometry_field_data.size()==geom_nodes.size());
254 for (
Uint g=0;
g<geom_nodes.size(); ++
g)
256 const Uint geom_node = geom_nodes[
g];
257 if (zone_node_idx.find(geom_node) != zone_node_idx.end())
259 const Uint node_idx = zone_node_idx[geom_node]-1;
261 const Real accumulated_weight = nodal_data_count[node_idx]/(nodal_data_count[node_idx]+1.0);
262 const Real add_weight = 1.0/(nodal_data_count[node_idx]+1.0);
263 nodal_data[node_idx] = accumulated_weight*nodal_data[node_idx] + add_weight*geometry_field_data[
g];
264 ++nodal_data_count[node_idx];
269 for (
Uint n=0;
n<nodal_data.size(); ++
n)
271 file << nodal_data[
n] <<
" ";
281 if (
options().value<bool>(
"cell_centred"))
282 file << nb_elems <<
"*" << 0.;
305 Entities const& elements = *elements_h;
312 Uint nb_ghost_elems = 0;
313 for (
Uint e=0;
e<nb_elems; ++
e)
318 nb_elems -= nb_ghost_elems;
321 std::string zone_name = elements.
parent()->uri().path();
322 boost::algorithm::replace_first(zone_name,
m_mesh->topology().uri().path()+
"/",
"");
323 std::set<std::string> zone_names;
324 if (zone_names.count(zone_name) == 0)
327 zone_names.insert(zone_name);
332 if (nb_elems == 0)
continue;
334 if (etype.
order() > 1)
336 throw NotImplemented(
FromHere(),
"Tecplot can only output P1 elements. A new P1 space should be created, and used as geometry space");
345 CFdebug <<
"smurf: writing zone header \"" << zone_name <<
"\"" <<
CFendl
347 <<
" nb_elems: " << nb_elems <<
CFendl;
352 if (cell_centered_var_ids.size() &&
options().
value<
bool>(
"cell_centred"))
355 file <<
",VARLOCATION=(["<<cell_centered_var_ids[0];
356 for (
Uint i=1; i<cell_centered_var_ids.size(); ++i)
357 file <<
","<<cell_centered_var_ids[i];
358 file <<
"]=CELLCENTERED)";
366 Entities const& elements = *elements_h;
373 Uint nb_ghost_elems = 0;
374 for (
Uint e=0;
e<nb_elems; ++
e)
379 nb_elems -= nb_ghost_elems;
384 if (nb_elems == 0)
continue;
388 std::vector<std::vector<unsigned> > ve; ve.reserve(connectivity.
size());
394 std::vector<unsigned> element; element.reserve(connectivity.
row_size());
396 element.push_back(n);
397 ve.push_back(element);
404 for (
unsigned c=0; c<ve.size(); ++c) {
405 const std::vector< unsigned > eng = ve[c];
406 std::vector< unsigned >& ent = ve[c];
416 for (
unsigned c=0; c<ve.size(); ++c) {
417 const std::vector< unsigned > eng = ve[c];
418 std::vector< unsigned >& ent = ve[c];
434 for (
unsigned c=0; c<ve.size(); ++c) {
435 const std::vector< unsigned > eng = ve[c];
436 std::vector< unsigned >& ent = ve[c];
452 for (
unsigned c=0; c<ve.size(); ++c) {
453 std::swap(ve[c][2],ve[c][3]);
454 std::swap(ve[c][6],ve[c][7]);
const ShapeFunction & shape_function() const
std::string name(ComponentWrapper &self)
std::string var_name(Uint i=0) const
boost::shared_ptr< Component > build_component(const std::string &builder_name, const std::string &name, const std::string &factory_type_name)
Safe pointer to an object. This is the supported method for referring to components.
common::ComponentBuilder< smurf::Writer, MeshWriter, LibSmurf > smurfWriter_Builder
Helper class to create the Builder and place it in the factory.
Space & geometry_space() const
bool m_enable_overlap
If true, writing of overlap will be enabled.
#define CF3_BREAK_LINE(f, x)
void writeZoneData(const ZoneType &type, const ZonePack &pack, const std::vector< std::vector< unsigned > > &ve, const std::vector< std::vector< double > > &vv=std::vector< std::vector< double > >(), const int sharefrom=0)
Handle< Mesh const > m_mesh
Handle to configured mesh.
std::vector< Uint > used_nodes(const mesh::Region ®ion, const mesh::Dictionary &dict)
ElementType & element_type() const
return the elementType
void writeMainHeader(const std::string &htitle, const std::vector< std::string > &hvnames)
bool is_ghost(const Uint idx) const
#define boost_foreach
lowercase version of BOOST_FOREACH
bool defined_for_entities(const Handle< Entities const > &entities) const
common::URI m_file_path
File path to be configured.
Conversions from and to std::string.
Real e()
Definition of the Unit charge [C].
virtual std::vector< std::string > get_extensions()
Dictionary & dict() const
Common_API std::string to_str(const T &v)
Converts to std::string.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
void writeZoneHeader(const ZoneType &type, const ZonePack &pack, const std::string &title, const unsigned I=1, const unsigned J=1, const unsigned K=1, const int &strand_id=int(-2))
Uint size() const
return the number of elements
Handle< Component > parent() const
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
SmURF::ZoneType zone_type(const ElementType &etype) const
GeoShape::Type shape() const
const Handle< Space const > & space(const Handle< Entities const > &entities) const
TableConstRow< Uint >::type ConstRow
the const type of a row in the internal structure of the table
VarType var_length(const std::string &vname) const
Return the length (in number of Real values occupied in the data row) of the variable of the given na...
Top-level namespace for coolfluid.
virtual Uint nb_nodes() const =0
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
Uint row_size(Uint i=0) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
unsigned int Uint
typedef for unsigned int
virtual RealRowVector value(const RealVector &local_coordinate) const =0
Compute the shape function values in the given local coordinate.
RowArrayRef row(const Uint r)
boost::shared_ptr< List< Uint > > build_used_nodes_list(const std::vector< Handle< Entities const > > &entities_vector, const Dictionary &dictionary, const bool include_ghost_elems, const bool follow_periodic_links)
Create a List containing unique entries of all the nodes used by a vector of entities...
std::vector< Handle< Field const > > m_fields
Handle to configured fields.
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
std::vector< Handle< Entities const > > m_filtered_entities
Handle to selected entities.
Most basic kernel library.
Connectivity & connectivity()
connectivity table to dictionary entries