Page MenuHomec4science

dumper_paraview.cc
No OneTemporary

File Metadata

Created
Sat, Jul 20, 06:02

dumper_paraview.cc

/**
* @file dumper_paraview.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Jul 09 21:59:47 2014
*
* @brief This dumper allows to generate paraview files for vizualization
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "dumper_paraview.hh"
#include "lib_continuum.hh"
#include "lib_dd.hh"
#include "lib_md.hh"
#include "lm_common.hh"
#include "ref_point_data.hh"
#include <communicator.hh>
#include <iomanip>
#include <sys/stat.h>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
DumperParaview::DumperParaview(const std::string &name)
: DumperInterface(name), dep_serie(false), p0_serie(false), vel_serie(false),
force_serie(false), proc_serie(false), stress_serie(false),
strain_serie(false), epot_serie(false), mass_serie(false),
charge_serie(false), id_serie(false), flag_compressed(false),
flag_text(false), flag_base64(false), alpha_serie(false),
e_density_serie(false), barycenters_serie(false),
temperature_serie(false), temperatureVar_serie(false),
heatCapacity_serie(false), heatRate_serie(false),
external_heatRate_serie(false), tag_serie(false) {}
/* -------------------------------------------------------------------------- */
DumperParaview::~DumperParaview() {}
/* -------------------------------------------------------------------------- */
void DumperParaview::init() {
DumperInterface::init();
if (flag_compressed)
paraHelper.setMode(ParaviewHelper::COMPRESSED);
if (flag_text)
paraHelper.setMode(ParaviewHelper::TEXT);
if (flag_base64)
paraHelper.setMode(ParaviewHelper::BASE64);
}
/* -------------------------------------------------------------------------- */
/* LMDESC PARAVIEW
This dumper ouputs paraview files from any domain description.
It admits several options that could be model dependent.
*/
/* LMEXAMPLE DUMPER para PARAVIEW INPUT md PROC DISP PREFIX /home/titeuf */
/* LMHERITANCE dumper */
void DumperParaview::declareParams() {
DumperInterface::declareParams();
/* LMKEYWORD PROC
Flag to request processor number to each DOF
*/
this->parseTag("PROC", proc_serie, false);
/* LMKEYWORD DISP
Flag to request displacements stored at each DOF
*/
this->parseTag("DISP", dep_serie, false);
/* LMKEYWORD ELECTRONIC_DENSITY
Flag to request electronic density (for EAM systems) stored at each atom
*/
this->parseTag("ELECTRONIC_DENSITY", e_density_serie, false);
/* LMKEYWORD ALPHA
Flag to request output of alpha line (for Arlequin testing)
*/
this->parseTag("ALPHA", alpha_serie, false);
/* LMKEYWORD P0
Flag to request output of initial position stored at each DOFs
*/
this->parseTag("P0", p0_serie, false);
/* LMKEYWORD TEMPERATURE
Only for continuum domains.
Flag to request output of temperature stored at each DOFs.
*/
this->parseTag("TEMPERATURE", temperature_serie, false);
/* LMKEYWORD TEMPERATURE_VARIATION
Only for continuum domains. Flag to request the output of the temperature
variation
at each DOFs.
*/
this->parseTag("TEMPERATURE_VARIATION", temperatureVar_serie, false);
/* LMKEYWORD HEAT_CAPACITY
return the heat capacity associated with nodal DOF. This
is applicable only for FE domains.
*/
this->parseTag("HEAT_CAPACITY", heatCapacity_serie, false);
/* LMKEYWORD HEAT_RATE
return the heat rate (residual) associated with nodal DOF. This
is applicable only for FE domains.
*/
this->parseTag("HEAT_RATE", heatRate_serie, false);
/* LMKEYWORD EXTERNAL_HEAT_RATE
return the external applied heat rate associated with nodal DOF. This
is applicable only for FE domains.
*/
this->parseTag("EXTERNAL_HEAT_RATE", external_heatRate_serie, false);
/* LMKEYWORD VEL
Flag to request output of velocity stored at each DOFs
*/
this->parseTag("VEL", vel_serie, false);
/* LMKEYWORD FORCE
Flag to request output of force stored at each DOFs
*/
this->parseTag("FORCE", force_serie, false);
/* LMKEYWORD APPLIED_FORCE
Flag to request output of applied force stored at each DOFs
*/
this->parseTag("APPLIED_FORCE", applied_force_serie, false);
/* LMKEYWORD STRESS
Flag to request output of stress field. This is implemented only for atomic
systems where the stress is computed using LAMMPS compute\_stress object.
*/
this->parseTag("STRESS", stress_serie, false);
/* LMKEYWORD STRAIN
Flag to request output of strain field. This is implemented only for FE
systems.
*/
this->parseTag("STRAIN", strain_serie, false);
/* LMKEYWORD EPOT
Flag to request the output of the potential energy associated to each
degree of freedom. Only for MD domains.
*/
this->parseTag("EPOT", epot_serie, false);
/* LMKEYWORD MASS
Flag to request output of mass stored to each degree of freedom. Only
applicable
to MD and FE systems.
*/
this->parseTag("MASS", mass_serie, false);
/* LMKEYWORD BARYCENTERS
Flag to request the output of the mass associated to each degree of freedom
*/
this->parseTag("BARYCENTERS", barycenters_serie, false);
/* LMKEYWORD CHARGE
Flag to request the output of the charge associated to each degree of
freedom.
Only for MD domains
*/
this->parseTag("CHARGE", charge_serie, false);
/* LMKEYWORD ID
Flag to request output of internal id associated to each degree of freedom.
*/
this->parseTag("ID", id_serie, false);
/* LMKEYWORD COMPRESSED
Flag to request output in compressed mode.
*/
this->parseTag("COMPRESSED", flag_compressed, false);
/* LMKEYWORD TEXT
The sections in XML paraview files are set to be written in simple TEXT
encoding.
*/
this->parseTag("TEXT", flag_text, false);
/* LMKEYWORD BASE64
The sections in XML paraview files are set to be written in base64
encoding.
*/
this->parseTag("BASE64", flag_base64, false);
/* LMKEYWORD TAG
provide the tag of the degree of freedom (for usage with lammps)
*/
this->parseTag("TAG", tag_serie, false);
/* LMKEYWORD ADDFIELD
provide the id of compute as an additional field
*/
this->parseKeyword("ADDFIELD", additional_fields);
/* LMKEYWORD BOUNDARY
flag to request output of nodal blockage
*/
this->parseKeyword("BOUNDARY", flag_boundary, false);
}
/* -------------------------------------------------------------------------- */
void DumperParaview::openPVTU() {
std::stringstream fname;
fname << this->getBaseName() << "_pvf" << std::setfill('0') << std::setw(4)
<< this->action_step << ".pvtu";
/* ouverture du fichier parallele vtk */
file.open(fname.str());
paraHelper.setOutputFile(file);
}
/* -------------------------------------------------------------------------- */
void DumperParaview::openVTU() {
std::string dirname;
dirname += this->prefix + "/" + this->getID() + "-VTUs";
mkdir(dirname.c_str(), 0755);
std::stringstream fname;
fname << dirname << "/" << this->getID() << "_pvf" << std::setfill('0')
<< std::setw(4) << this->action_step << ".proc" << std::setfill('0')
<< std::setw(4) << lm_my_proc_id << ".vtu";
file.open(fname.str(), "wb+", flag_compressed);
paraHelper.setOutputFile(file);
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
enable_if_md<Cont> DumperParaview::dump(Cont &cont) {
constexpr UInt Dim = Cont::Dim;
UInt nb = cont.size();
Communicator &comm = Communicator::getCommunicator();
CommGroup group = cont.getCommGroup();
UInt my_rank = comm.groupRank(lm_my_proc_id, group);
UInt group_size = comm.getNBprocsOnGroup(group);
if (my_rank == 0) {
openPVTU();
file.printf("<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" ");
file.printf("byte_order=\"LittleEndian\">\n");
file.printf("<PUnstructuredGrid GhostLevel=\"0\">\n");
file.printf("<PPointData>\n");
if (dep_serie)
paraHelper.PDataArray("displacements", 3);
if (p0_serie)
paraHelper.PDataArray("P0", 3);
if (vel_serie)
paraHelper.PDataArray("velocities", 3);
if (force_serie)
paraHelper.PDataArray("force", 3);
if (stress_serie)
paraHelper.PDataArray("stress", 6);
if (barycenters_serie)
paraHelper.PDataArray("barycenters", 3);
if (proc_serie)
paraHelper.PDataArray("procs", 1);
if (id_serie)
paraHelper.PDataArray("id", 1);
if (mass_serie)
paraHelper.PDataArray("mass", 1);
if (epot_serie)
paraHelper.PDataArray("epot", 1);
if (charge_serie)
paraHelper.PDataArray("charge", 1);
if (alpha_serie)
paraHelper.PDataArray("alpha", 1);
if (tag_serie)
paraHelper.PDataArray("tag", 1);
if (e_density_serie)
paraHelper.PDataArray("electronic_density", 1);
for (UInt i = 0; i < additional_fields.size(); ++i) {
FilterID additional_field = additional_fields[i];
if (additional_field != invalidFilter) {
LM_TOIMPLEMENT;
// ComputeInterface *ptr = dynamic_cast<ComputeInterface *>(
// FilterManager::getManager().getObject(additional_field));
// if (ptr) {
// ptr->build();
// paraHelper.PDataArray(additional_field, ptr->getDim());
// }
}
}
file.printf("</PPointData>");
file.printf("<PPoints><PDataArray type=\"Float64\" "
"NumberOfComponents=\"3\" format=\"ascii\"/></PPoints>");
if (group_size > 1)
for (UInt l = 0; l < group_size; ++l) {
file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
this->getID().c_str(), this->getID().c_str(),
this->action_step, comm.realRank(l, group));
}
else
file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
this->getID().c_str(), this->getID().c_str(),
this->action_step, lm_my_proc_id);
file.printf("</PUnstructuredGrid></VTKFile>");
file.close();
}
openVTU();
if (nb)
paraHelper.write_header(nb, 1);
else
paraHelper.write_header(nb, 0);
UnitsConverter unit;
unit.setInUnits(code_unit_system);
unit.setOutUnits(this->dump_unit_system);
unit.computeConversions();
paraHelper.startDofList();
for (auto &&at : cont) {
auto X = at.position0();
for (UInt i = 0; i < Dim; ++i)
paraHelper.pushReal(X[i] * unit.getConversion<Length>());
for (UInt i = Dim; i < 3; ++i)
paraHelper.pushReal(0.0);
}
paraHelper.endDofList();
paraHelper.startCellsConnectivityList();
for (UInt i = 0; i < nb; ++i) {
paraHelper.pushInteger(i);
}
paraHelper.endCellsConnectivityList();
paraHelper.startCellsoffsetsList();
paraHelper.pushInteger(nb);
paraHelper.endCellsoffsetsList();
paraHelper.startCellstypesList();
if (nb) {
paraHelper.pushInteger(2);
}
paraHelper.endCellstypesList();
paraHelper.startPointDataList();
if (dep_serie) {
paraHelper.startData("displacements", 3);
for (auto &&at : cont) {
Vector<Dim> u = at.displacement();
u *= unit.getConversion<Length>();
paraHelper.push(u, 3);
}
paraHelper.endData();
}
if (p0_serie) {
paraHelper.startData("P0", 3);
for (auto &&at : cont) {
Vector<Dim> u = at.position0();
u *= unit.getConversion<Length>();
paraHelper.push(u, 3);
}
paraHelper.endData();
}
if (vel_serie) {
paraHelper.startData("velocities", 3);
for (auto &&at : cont) {
Vector<Dim> v = at.velocity();
paraHelper.push(v, 3);
}
paraHelper.endData();
}
if (force_serie) {
paraHelper.startData("force", 3);
for (auto &&at : cont) {
Vector<Dim> f = at.force();
paraHelper.push(f, 3);
}
paraHelper.endData();
}
if (stress_serie) {
paraHelper.startData("stress", 6);
LM_TOIMPLEMENT;
// for (auto && at : cont) {
// LM_TOIMPLEMENT;
// 1.60217653e-19 / 1e-30 / 1e9 = 1.60217653e2 is for conversion from
// eV/A^3 to GigaPascals
// Real x = at.stress(0) * 1.60217653e2;
// Real y = at.stress(1) * 1.60217653e2;
// Real z = at.stress(2) * 1.60217653e2;
//
// paraHelper.pushReal(x);
// paraHelper.pushReal(y);
// paraHelper.pushReal(z);
//
// x = at.stress(3) * 1.60217653e2;
// y = at.stress(4) * 1.60217653e2;
// z = at.stress(5) * 1.60217653e2;
//
// paraHelper.pushReal(x);
// paraHelper.pushReal(y);
// paraHelper.pushReal(z);
//}
paraHelper.endData();
}
if (barycenters_serie) {
paraHelper.startData("barycenters", 3);
Vector<Dim> X = Vector<Dim>::Zero();
UInt cpt = 0;
for (auto &&at : cont) {
X += at.position();
++cpt;
}
X /= cpt;
for (UInt i = 0; i < cont.size(); ++i) {
paraHelper.push(X, Dim);
}
paraHelper.endData();
}
if (proc_serie) {
paraHelper.startData("procs", 1);
for (UInt i = 0; i < cont.size(); ++i) {
paraHelper.pushReal(lm_my_proc_id);
}
paraHelper.endData();
}
if (id_serie) {
paraHelper.startData("id", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.id());
}
paraHelper.endData();
}
if (mass_serie) {
paraHelper.startData("mass", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.mass());
}
paraHelper.endData();
}
if (epot_serie) {
paraHelper.startData("epot", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.getEPot());
}
paraHelper.endData();
}
if (charge_serie) {
paraHelper.startData("charge", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.charge());
}
paraHelper.endData();
}
if (alpha_serie) {
paraHelper.startData("alpha", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.alpha());
}
paraHelper.endData();
}
if (e_density_serie) {
paraHelper.startData("electronic_density", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.electronic_density());
}
paraHelper.endData();
}
if (tag_serie) {
paraHelper.startData("tag", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.tag());
}
paraHelper.endData();
}
for (UInt i = 0; i < additional_fields.size(); ++i) {
FilterID additional_field = additional_fields[i];
if (additional_field != invalidFilter) {
LM_TOIMPLEMENT;
// ComputeInterface *ptr = dynamic_cast<ComputeInterface *>(
// FilterManager::getManager().getObject(additional_field));
// if (ptr) {
// ptr->build();
// dumpField(additional_field, cont, *ptr, ptr->getDim());
// }
}
}
paraHelper.endPointDataList();
paraHelper.write_conclusion();
file.close();
}
/* -------------------------------------------------------------------------- */
template <typename Cont> enable_if_mesh<Cont> DumperParaview::dump(Cont &cont) {
constexpr UInt Dim = Cont::Dim;
Communicator &comm = Communicator::getCommunicator();
CommGroup group = cont.getCommGroup();
UInt my_rank = comm.groupRank(lm_my_proc_id, group);
UInt group_size = comm.getNBprocsOnGroup(group);
if (my_rank == 0) {
openPVTU();
file.printf("<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" ");
// #ifdef BIG_ENDIAN
// file.printf("byte_order=\"BigEndian\">\n");
// #else
file.printf("byte_order=\"LittleEndian\">\n");
// #endif
file.printf("<PUnstructuredGrid GhostLevel=\"1\">\n");
file.printf("<PPointData>\n");
if (dep_serie)
paraHelper.PDataArray("displacements", 3);
if (p0_serie)
paraHelper.PDataArray("P0", 3);
if (vel_serie)
paraHelper.PDataArray("velocities", 3);
if (force_serie)
paraHelper.PDataArray("force", 3);
if (applied_force_serie)
paraHelper.PDataArray("applied_force", 3);
if (temperature_serie)
paraHelper.PDataArray("temperature", 1);
if (temperatureVar_serie)
paraHelper.PDataArray("temperatureVariation", 1);
if (heatCapacity_serie)
paraHelper.PDataArray("heatCapacity", 1);
if (heatRate_serie)
paraHelper.PDataArray("heatRate", 1);
if (external_heatRate_serie)
paraHelper.PDataArray("externalHeatRate", 1);
if (id_serie)
paraHelper.PDataArray("id", 1);
if (mass_serie)
paraHelper.PDataArray("mass", 1);
if (flag_boundary)
paraHelper.PDataArray("blocked_dof", 3);
if (barycenters_serie)
paraHelper.PDataArray("barycenters", 3);
if (proc_serie)
paraHelper.PDataArray("procs", 1);
if (alpha_serie)
paraHelper.PDataArray("alpha", 1);
for (UInt i = 0; i < additional_fields.size(); ++i) {
FilterID additional_field = additional_fields[i];
if (additional_field != invalidFilter) {
LM_TOIMPLEMENT;
// ComputeInterface *ptr = dynamic_cast<ComputeInterface *>(
// FilterManager::getManager().getObject(additional_field));
// if (ptr) {
// ptr->build();
// paraHelper.PDataArray(additional_field, ptr->getDim());
// }
}
}
file.printf("</PPointData>");
if (stress_serie || strain_serie) {
file.printf("<PCellData>\n");
}
if (stress_serie && Dim == 3)
paraHelper.PDataArray("stress", 6);
if (strain_serie && Dim == 3)
paraHelper.PDataArray("strain", 6);
if (stress_serie && Dim == 2)
paraHelper.PDataArray("stress", 3);
if (strain_serie && Dim == 2)
paraHelper.PDataArray("strain", 3);
if (stress_serie || strain_serie) {
file.printf("</PCellData>\n");
}
file.printf("<PPoints><PDataArray type=\"Float64\" "
"NumberOfComponents=\"3\" format=\"ascii\"/></PPoints>");
if (group_size > 1)
for (UInt l = 0; l < group_size; ++l) {
file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
this->getID().c_str(), this->getID().c_str(),
this->action_step, l);
}
else
file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
this->getID().c_str(), this->getID().c_str(),
this->action_step, lm_my_proc_id);
file.printf("</PUnstructuredGrid></VTKFile>");
file.close();
}
openVTU();
typename Cont::ContainerElems &contElems = cont.getContainerElems();
typename Cont::ContainerNodes &contNodes = cont.getContainerNodes();
UInt nb = contNodes.size(dt_all);
UInt sizes = contElems.size();
std::vector<UInt> nodes;
UInt compteur;
/* start */
paraHelper.write_header(nb, sizes);
UnitsConverter unit;
unit.setInUnits(code_unit_system);
unit.setOutUnits(this->dump_unit_system);
unit.computeConversions();
paraHelper.startDofList();
for (auto &&n : contNodes) {
Vector<Dim> X = n.position0();
for (UInt i = 0; i < Dim; ++i)
paraHelper.pushReal(X[i] * unit.getConversion<Length>());
for (UInt i = Dim; i < 3; ++i)
paraHelper.pushReal(0.0);
}
paraHelper.endDofList();
paraHelper.startCellsConnectivityList();
for (auto &&el : contElems) {
if (el.isAltered())
nodes = el.getAlteredConnectivity();
else
el.localIndexes(nodes);
UInt nd_sz = nodes.size();
if (nd_sz == 10)
nd_sz = 4;
for (UInt j = 0; j < nd_sz; ++j) {
paraHelper.pushInteger(nodes[j]);
}
}
paraHelper.endCellsConnectivityList();
paraHelper.startCellsoffsetsList();
compteur = 0;
for (auto &&el : contElems) {
el.localIndexes(nodes);
if (nodes.size() == 10)
compteur += 4;
else
compteur += nodes.size();
paraHelper.pushInteger(compteur);
}
paraHelper.endCellsoffsetsList();
paraHelper.startCellstypesList();
UInt code_type = UINT_MAX;
for (auto &&el : contElems) {
el.localIndexes(nodes);
switch (nodes.size()) {
case 2:
code_type = 3;
break;
case 3:
code_type = 5;
break;
case 8:
code_type = 12;
break;
case 4:
code_type = 10;
break;
case 10:
code_type = 10;
break;
default:
LM_FATAL("unable to dump for VTK : " << nodes.size());
}
paraHelper.pushInteger(code_type);
}
paraHelper.endCellstypesList();
paraHelper.startPointDataList();
if (dep_serie) {
paraHelper.startData("displacements", 3);
for (auto &&n : contNodes) {
auto X = n.displacement() * unit.getConversion<Length>();
paraHelper.push(X, 3);
}
paraHelper.endData();
}
if (p0_serie) {
paraHelper.startData("P0", 3);
for (auto &&n : contNodes) {
auto X = n.position0() * unit.getConversion<Length>();
paraHelper.push(X, 3);
}
paraHelper.endData();
}
if (vel_serie) {
paraHelper.startData("velocities", 3);
for (auto &&n : contNodes) {
auto X = n.velocity();
paraHelper.push(X, 3);
}
paraHelper.endData();
}
if (force_serie) {
paraHelper.startData("force", 3);
UInt cpt = 0;
for (auto &&n : contNodes) {
auto X = n.force();
paraHelper.push(X, 3);
++cpt;
}
paraHelper.endData();
}
// if (applied_force_serie) {
// paraHelper.startData("applied_force", 3);
// UInt cpt = 0;
// for (RefNd n = itNodes.getFirst(); !itNodes.end(); n = itNodes.getNext())
// {
// Real x = n.appliedForce(0);
// Real y = 0;
// Real z = 0;
// if (Dim > 1)
// y = n.appliedForce(1);
// if (Dim > 2)
// z = n.appliedForce(2);
// paraHelper.pushReal(x);
// paraHelper.pushReal(y);
// paraHelper.pushReal(z);
// ++cpt;
// }
// paraHelper.endData();
// }
if (temperature_serie) {
paraHelper.startData("temperature", 1);
for (auto &&n : contNodes) {
Real t = n.temperature();
paraHelper.pushReal(t);
}
paraHelper.endData();
}
if (temperatureVar_serie) {
paraHelper.startData("temperatureVariation", 1);
for (auto &&n : contNodes) {
Real t = n.temperatureVar();
paraHelper.pushReal(t);
}
paraHelper.endData();
}
if (heatCapacity_serie) {
paraHelper.startData("heatCapacity", 1);
for (auto &&n : contNodes) {
Real t = n.capacity();
paraHelper.pushReal(t);
}
paraHelper.endData();
}
if (heatRate_serie) {
paraHelper.startData("heatRate", 1);
for (auto &&n : contNodes) {
Real t = n.heatRate();
paraHelper.pushReal(t);
}
paraHelper.endData();
}
if (external_heatRate_serie) {
paraHelper.startData("externalHeatRate", 1);
for (auto &&n : contNodes) {
Real t = n.externalHeatRate();
paraHelper.pushReal(t);
}
paraHelper.endData();
}
if (id_serie) {
paraHelper.startData("id", 1);
for (auto &&n : contNodes) {
paraHelper.pushReal(n.id());
}
paraHelper.endData();
}
if (mass_serie) {
paraHelper.startData("mass", 1);
for (auto &&n : contNodes) {
Real mass = n.mass() * unit.getConversion<Mass>();
paraHelper.pushReal(mass);
}
paraHelper.endData();
}
if (flag_boundary) {
paraHelper.startData("blocked_dof", 3);
for (auto &&n : contNodes) {
for (UInt i = 0; i < Dim; ++i) {
Real is_blocked = n.boundary(i);
paraHelper.pushReal(is_blocked);
}
}
paraHelper.endData();
}
if (barycenters_serie) {
paraHelper.startData("barycenters", 3);
Vector<Dim> X = Vector<Dim>::Zero();
UInt cpt = 0;
for (auto &&n : contNodes) {
X += n.position0();
++cpt;
}
X /= cpt;
for (UInt i = 0; i < contNodes.size(); ++i) {
paraHelper.push(X, 3);
}
paraHelper.endData();
}
if (proc_serie) {
paraHelper.startData("procs", 1);
for (UInt i = 0; i < contNodes.size(); ++i) {
paraHelper.pushReal(lm_my_proc_id);
}
paraHelper.endData();
}
if (alpha_serie) {
paraHelper.startData("alpha", 1);
for (auto &&n : contNodes) {
paraHelper.pushReal(n.alpha());
}
paraHelper.endData();
}
for (UInt i = 0; i < additional_fields.size(); ++i) {
FilterID additional_field = additional_fields[i];
if (additional_field != invalidFilter) {
LM_TOIMPLEMENT;
// ComputeInterface *ptr = dynamic_cast<ComputeInterface *>(
// FilterManager::getManager().getObject(additional_field));
// if (ptr) {
// dumpField(additional_field, cont, *ptr, ptr->getDim());
// }
}
}
paraHelper.endPointDataList();
if (stress_serie || strain_serie)
paraHelper.startCellDataList();
if (stress_serie) {
if (Dim == 3)
paraHelper.startData("stress", 6);
if (Dim == 2)
paraHelper.startData("stress", 3);
for (auto &&el : contElems) {
// order of dimensions for paraview: xx, yy, zz, xy yz xz
// order of dimensions for libmultiscale : akantu COLmajor
paraHelper.pushReal(el.stress(0 + 0 * Dim) *
unit.getConversion<Pressure>());
if (Dim == 2) {
paraHelper.pushReal(el.stress(1 + 1 * Dim) *
unit.getConversion<Pressure>());
paraHelper.pushReal(el.stress(0 + 1 * Dim) *
unit.getConversion<Pressure>());
} else if (Dim == 3) {
paraHelper.pushReal(el.stress(1 + 1 * Dim) *
unit.getConversion<Pressure>());
paraHelper.pushReal(el.stress(2 + 2 * Dim) *
unit.getConversion<Pressure>());
paraHelper.pushReal(el.stress(0 + 1 * Dim) *
unit.getConversion<Pressure>());
paraHelper.pushReal(el.stress(1 + 2 * Dim) *
unit.getConversion<Pressure>());
paraHelper.pushReal(el.stress(0 + 2 * Dim) *
unit.getConversion<Pressure>());
}
}
paraHelper.endData();
}
if (strain_serie) {
if (Dim == 3)
paraHelper.startData("strain", 6);
if (Dim == 2)
paraHelper.startData("strain", 3);
for (auto &&el : contElems) {
// order of dimensions for paraview: xx, yy, zz, xy yz xz,
// order of dimensions for libmultiscale : akantu COLmajor
paraHelper.pushReal(el.strain(0 + 0 * Dim));
if (Dim == 2) {
paraHelper.pushReal(el.strain(1 + 1 * Dim));
paraHelper.pushReal(el.strain(0 + 1 * Dim));
} else if (Dim == 3) {
paraHelper.pushReal(el.strain(1 + 1 * Dim));
paraHelper.pushReal(el.strain(2 + 2 * Dim));
paraHelper.pushReal(el.strain(0 + 1 * Dim));
paraHelper.pushReal(el.strain(1 + 2 * Dim));
paraHelper.pushReal(el.strain(0 + 2 * Dim));
}
}
paraHelper.endData();
}
if (stress_serie || strain_serie)
paraHelper.endCellDataList();
// paraHelper.startData(file,"deformation",3);
// for (RefElt el = itNodes.GetFirstElem();!itNodes.endElem();el =
// itNodes.getNextElem()) {
// file.printf("%.15e",el.GetDeformations(0));
// if (Dim > 1)
// file.printf(" %.15e",el.GetDeformations(1));
// else
// file.printf(" %.15e",0.0);
// if (Dim > 2)
// file.printf(" %.15e",el.GetDeformations(2));
// else
// file.printf(" %.15e",0.0);
// file.printf("\n");
// }
// paraHelper.endData(file);
// paraHelper.endCellDataList(file);
paraHelper.write_conclusion();
file.close();
}
/* -------------------------------------------------------------------------- */
// template <typename Cont> void DumperParaview::dump(Cont &cont) {
// constexpr UInt Dim = Cont::Dim;
// typedef typename Cont::Ref RefNode;
// typename Cont::ContainerNodes &cNodes = cont.getContainerNodes();
// Communicator &comm = Communicator::getCommunicator();
// CommGroup group = cont.getCommGroup();
// UInt my_rank = comm.groupRank(lm_my_proc_id, group);
// UInt group_size = comm.getNBprocsOnGroup(group);
// if (my_rank == 0) {
// openPVTU();
// file.printf("<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" ");
// file.printf("byte_order=\"LittleEndian\">\n");
// file.printf("<PUnstructuredGrid GhostLevel=\"0\">\n");
// file.printf("<PPointData>\n");
// if (force_serie)
// paraHelper.PDataArray("force", 3);
// if (stress_serie)
// paraHelper.PDataArray("stress", 6);
// paraHelper.PDataArray("kind", 1);
// file.printf("</PPointData>");
// file.printf("<PPoints><PDataArray type=\"Float64\" "
// "NumberOfComponents=\"3\" format=\"ascii\"/></PPoints>");
// if (group_size > 1)
// for (UInt l = 0; l < group_size; ++l) {
// file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
// this->getID().c_str(), this->getID().c_str(),
// this->action_step, l);
// }
// else
// file.printf("<Piece Source=\"%s-VTUs/%s_pvf%.4d.proc%.4d.vtu\"/>\n",
// this->getID().c_str(), this->getID().c_str(),
// this->action_step, lm_my_proc_id);
// file.printf("</PUnstructuredGrid></VTKFile>");
// file.close();
// }
// openVTU();
// UInt nbrNodes = cNodes.size();
// UInt nbrElems = 0;
// typename Cont::iterator it = cNodes.begin();
// // for (RefNode nd = it.getFirst(); !it.end(); nd = it.getNext()) {
// // ++nbrNodes;
// // if (nd.getConstraint() == 7) {
// // ++nbrElems0;
// // }
// // }
// // nbrElems = nbrElems0 / 2;
// if (nbrElems)
// paraHelper.write_header(nbrNodes, nbrElems);
// else
// paraHelper.write_header(nbrNodes, 1);
// UnitsConverter unit;
// unit.setInUnits(code_unit_system);
// unit.setOutUnits(code_unit_system);
// unit.computeConversions();
// std::vector<UInt> considered_indices;
// std::vector<UInt> offsets;
// // UInt accumulated_offset = 0;
// paraHelper.startDofList();
// std::vector<UInt> constraints;
// for (auto &&nd : cNodes) {
// RefNode nextNode = nd;
// // UInt cnst = nd.getConstraint();
// UInt idx = nd.getIndex();
// considered_indices.push_back(idx);
// Vector<Dim> X = nextNode.position() * unit.getConversion<Length>();
// paraHelper.push(X, Dim);
// }
// paraHelper.endDofList();
// if (offsets.size() != nbrElems)
// LM_FATAL("problem: number of elements:" << nbrElems << " but offset size:"
// << offsets.size());
// paraHelper.startCellsConnectivityList();
// for (UInt i = 0; i < nbrNodes; ++i) {
// paraHelper.pushInteger(i);
// }
// if (offsets.size() == 0)
// paraHelper.pushInteger(0);
// paraHelper.endCellsConnectivityList();
// paraHelper.startCellsoffsetsList();
// if (offsets.size() == 0) {
// paraHelper.pushInteger(nbrNodes + 1);
// } else {
// for (UInt i = 0; i < nbrElems; ++i) {
// paraHelper.pushInteger(offsets[i]);
// }
// }
// paraHelper.endCellsoffsetsList();
// paraHelper.startCellstypesList();
// if (nbrNodes) {
// if (offsets.size() == 0) {
// paraHelper.pushInteger(4);
// } else {
// for (UInt i = 0; i < nbrElems; ++i) {
// paraHelper.pushInteger(4);
// }
// }
// }
// paraHelper.endCellstypesList();
// paraHelper.startPointDataList();
// if (force_serie) {
// paraHelper.startData("force", 3);
// for (auto &&nd : cNodes) {
// auto f = nd.force();
// paraHelper.push(f, Dim);
// }
// paraHelper.endData();
// }
// if (stress_serie) {
// LM_TOIMPLEMENT;
// // paraHelper.startData("stress", 6);
// // for (auto &&nd : cNodes) {
// // auto s = nd.stress();
// // paraHelper.push(s, Dim*(Dim+1)/2);
// // }
// // paraHelper.endData();
// }
// paraHelper.startData("kind", 1);
// UInt count = 0;
// for (auto &&nd : cNodes) {
// if (nbrElems == 0) {
// paraHelper.pushInteger(nd.getConstraint());
// } else {
// paraHelper.pushInteger(constraints[count]);
// ++count;
// }
// }
// paraHelper.endData();
// paraHelper.endPointDataList();
// paraHelper.write_conclusion();
// file.close();
// }
/* -------------------------------------------------------------------------- */
DECLARE_DUMPER_MAKE_CALL(DumperParaview);
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__

Event Timeline