Page MenuHomec4science

dumper_paraview_atom.cc
No OneTemporary

File Metadata

Created
Mon, Oct 28, 19:15

dumper_paraview_atom.cc

/**
* @file dumper_paraview_atom.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Thu Sep 18 16:13:19 2014
*
* @brief This dumper allows to generate paraview files for vizualization
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* The LibMultiScale is a C++ parallel framework for the multiscale
* coupling methods dedicated to material simulations. This framework
* provides an API which makes it possible to program coupled simulations
* and integration of already existing codes.
*
* This Project was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*
*/
/* -------------------------------------------------------------------------- */
#include "dumper_paraview.hh"
#include "communicator.hh"
#include "compute.hh"
#include "container_mesh.hh"
#include "filter.hh"
#include "filter_manager.hh"
#include "lib_md.hh"
#include "lm_common.hh"
#include "ref_point_data.hh"
#include "units_converter.hh"
#include <iomanip>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont> void DumperParaview<Cont>::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) {
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) {
// UInt cpt=0;
paraHelper.startData("id", 1);
for (auto &&at : cont) {
paraHelper.pushReal(at.id());
// paraHelper.pushReal(cpt);
//++cpt;
}
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) {
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();
}
/* -------------------------------------------------------------------------- */
DECLARE_DUMPER_REF(DumperParaview, LIST_ATOM_MODEL);
DECLARE_DUMPER_REFPOINT(DumperParaview);
DECLARE_DUMPER_GENERIC_MESH(DumperParaview);
__END_LIBMULTISCALE__

Event Timeline