Page MenuHomec4science

dumper_paraview_dd.cc
No OneTemporary

File Metadata

Created
Mon, Nov 4, 05:23

dumper_paraview_dd.cc

/**
* @file dumper_dd_paraview.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Jaehyun Cho <jaehyun.cho@epfl.ch>
*
* @date Fri Jul 11 15:47:44 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 "communicator.hh"
#include "dumper_paraview.hh"
#include "filter.hh"
#include "lib_dd.hh"
#include "lm_common.hh"
#include "units_converter.hh"
/* -------------------------------------------------------------------------- */
#include <algorithm>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont> void DumperParaview<Cont>::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_REF(DumperParaview, LIST_DD_MODEL)
__END_LIBMULTISCALE__

Event Timeline