40 #define CF3_BREAK_LINE(f,x) { if( x+1 % 10) { f << "\n"; } }
48 Writer::Writer(
const std::string&
name )
53 .description(
"True if discontinuous fields are to be plotted as cell-centred fields");
60 std::vector<std::string> extensions;
61 extensions.push_back(
".plt");
70 boost::filesystem::fstream file;
72 if (PE::Comm::instance().size() > 1)
74 path = boost::filesystem::basename(path) +
"_P" +
to_str(PE::Comm::instance().rank()) + boost::filesystem::extension(path);
77 file.open(path,std::ios_base::out);
80 throw boost::filesystem::filesystem_error( path.string() +
" failed to open",
81 boost::system::error_code() );
94 file <<
"TITLE = COOLFluiD Mesh Data" <<
"\n";
95 file <<
"VARIABLES = ";
97 Uint dimension =
m_mesh->geometry_fields().coordinates().row_size();
99 for (
Uint i = 0; i < dimension ; ++i)
101 file <<
" \"x" << i <<
"\" ";
104 std::vector<Uint> cell_centered_var_ids;
105 Uint zone_var_id(dimension);
108 const Field& field = *field_ptr;
112 std::string var_name = field.
var_name(iVar);
114 if ( static_cast<Uint>(var_type) > 1)
116 for (
Uint i=0; i<static_cast<Uint>(var_type); ++i)
118 file <<
" \"" << var_name <<
"["<<i<<
"]\"";
121 cell_centered_var_ids.push_back(zone_var_id);
126 file <<
" \"" << var_name <<
"\"";
129 cell_centered_var_ids.push_back(zone_var_id);
142 Entities const& elements = *elements_h;
149 Uint nb_ghost_elems = 0;
150 for (
Uint e=0;
e<nb_elems; ++
e)
155 nb_elems -= nb_ghost_elems;
158 std::string zone_name = elements.
parent()->uri().path();
159 boost::algorithm::replace_first(zone_name,
m_mesh->topology().uri().path()+
"/",
"");
160 std::set<std::string> zone_names;
161 if (zone_names.count(zone_name) == 0)
164 zone_names.insert(zone_name);
173 if (etype.
order() > 1)
175 throw NotImplemented(
FromHere(),
"Tecplot can only output P1 elements. A new P1 space should be created, and used as geometry space");
180 std::map<Uint,Uint> zone_node_idx;
181 for (
Uint n=0;
n<used_nodes.size(); ++
n)
182 zone_node_idx[ used_nodes[
n] ] =
n+1;
184 const Uint nbCellsInType = elements.
size();
191 <<
" T=\"STEP"<<
m_mesh->metadata().properties().value<
Uint>(
"iter") <<
":" << zone_name <<
"\""
192 <<
", STRANDID="<<zone_idx
193 <<
", SOLUTIONTIME="<<
m_mesh->metadata().properties().value<Real>(
"time")
194 <<
", N=" << used_nodes.size()
195 <<
", E=" << nb_elems
196 <<
", DATAPACKING=BLOCK"
198 if (cell_centered_var_ids.size() &&
options().
value<
bool>(
"cell_centred"))
200 file <<
",VARLOCATION=(["<<cell_centered_var_ids[0];
201 for (
Uint i=1; i<cell_centered_var_ids.size(); ++i)
202 file <<
","<<cell_centered_var_ids[i];
203 file <<
"]=CELLCENTERED)";
213 file.setf(std::ios::scientific,std::ios::floatfield);
218 for (
Uint d = 0; d < dimension; ++d)
220 file <<
"\n### variable x" << d <<
"\n\n";
224 file << coordinates[
n][d] <<
" ";
234 const Field& field = *field_ptr;
239 std::string var_name = field.
var_name(iVar);
240 file <<
"\n### variable " << var_name <<
"\n\n";
242 for (
Uint i=0; i<static_cast<Uint>(var_type); ++i)
247 if ( &field.
dict() == &
m_mesh->geometry_fields() )
251 file << field[
n][var_idx] <<
" ";
261 const Space& field_space = field.
space(elements);
264 std::vector<Real> nodal_data(used_nodes.size(),0.);
269 for (
Uint g=0;
g<interpolation.rows(); ++
g)
271 interpolation.row(
g) = sf.
value(geometry_local_coords.row(
g));
286 field_data[iState] = field[field_index[iState]][var_idx];
290 RealVector geometry_field_data = interpolation*field_data;
293 cf3_assert(geometry_field_data.size()==geom_nodes.size());
295 for (
Uint g=0;
g<geom_nodes.size(); ++
g)
297 const Uint geom_node = geom_nodes[
g];
298 const Uint node_idx = zone_node_idx[geom_node]-1;
300 nodal_data[node_idx] = geometry_field_data[
g];
304 for (
Uint n=0;
n<nodal_data.size(); ++
n)
306 file << nodal_data[
n] <<
" ";
318 const Space& field_space = field.
space(elements);
333 field_data[iState] = field[field_index[iState]][var_idx];
337 RealVector local_coords = P0_cell_centred->local_coordinates().
row(0);
343 file << cell_centred_data <<
" ";
351 std::vector<Real> nodal_data(used_nodes.size(),0.);
352 std::vector<Uint> nodal_data_count(used_nodes.size(),0u);
357 for (
Uint g=0;
g<interpolation.rows(); ++
g)
359 interpolation.row(
g) = sf.
value(geometry_local_coords.row(
g));
369 field_data[iState] = field[field_index[iState]][var_idx];
373 RealVector geometry_field_data = interpolation*field_data;
376 cf3_assert(geometry_field_data.size()==geom_nodes.size());
378 for (
Uint g=0;
g<geom_nodes.size(); ++
g)
380 const Uint geom_node = geom_nodes[
g];
381 if (zone_node_idx.find(geom_node) != zone_node_idx.end())
383 const Uint node_idx = zone_node_idx[geom_node]-1;
385 const Real accumulated_weight = nodal_data_count[node_idx]/(nodal_data_count[node_idx]+1.0);
386 const Real add_weight = 1.0/(nodal_data_count[node_idx]+1.0);
387 nodal_data[node_idx] = accumulated_weight*nodal_data[node_idx] + add_weight*geometry_field_data[
g];
388 ++nodal_data_count[node_idx];
393 for (
Uint n=0;
n<nodal_data.size(); ++
n)
395 file << nodal_data[
n] <<
" ";
405 if (
options().value<bool>(
"cell_centred"))
406 file << nb_elems <<
"*" << 0.;
408 file << used_nodes.size() <<
"*" << 0.;
417 file <<
"\n### connectivity\n\n";
427 Uint const&
n = connectivity[
e][0];
428 file << zone_node_idx[
n] <<
" "
429 << zone_node_idx[
n] <<
" ";
435 file << zone_node_idx[
n] <<
" ";
462 #undef CF3_BREAK_LINE
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.
Helper class to create the Builder and place it in the factory.
Space & geometry_space() const
virtual const RealMatrix & local_coordinates() const =0
bool m_enable_overlap
If true, writing of overlap will be enabled.
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
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].
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.
Uint size() const
return the number of elements
#define cf3_assert_desc(m, a)
virtual std::vector< std::string > get_extensions()
Handle< Component > parent() const
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
GeoShape::Type shape() const
common::ComponentBuilder< tecplot::Writer, MeshWriter, LibTecplot > atecplotWriter_Builder
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.
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
std::string zone_type(const ElementType &etype) const
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...
Handle< Component > handle()
Get a handle to the component.
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.
#define CF3_BREAK_LINE(f, x)
Most basic kernel library.
Connectivity & connectivity()
connectivity table to dictionary entries
std::string shape_name() const
void write_file(std::fstream &file)
bool discontinuous() const