diff --git a/src/dumper/dumper_dd_paraview.cc b/src/dumper/dumper_dd_paraview.cc index 16e2116..1c8e1a1 100644 --- a/src/dumper/dumper_dd_paraview.cc +++ b/src/dumper/dumper_dd_paraview.cc @@ -1,192 +1,261 @@ /** * @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 "lm_common.hh" #include "dumper_paraview.hh" #include "filter.hh" #include "lib_dd.hh" #include "units_converter.hh" #include "communicator.hh" /* -------------------------------------------------------------------------- */ #include <sys/stat.h> #include <sys/types.h> /* -------------------------------------------------------------------------- */ __BEGIN_LIBMULTISCALE__ template <typename Cont> void DumperParaview<Cont>::dump(Cont & cont){ static const 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 nb = 0; + UInt nbrNodes = 0; + UInt nbrElems0= 0; + UInt nbrElems = 0; typename Cont::iterator it = cNodes.getIterator(); - for (RefNode nd = it.getFirst(); !it.end(); nd = it.getNext()) - ++nb; + for (RefNode nd = it.getFirst(); !it.end(); nd = it.getNext()){ + ++nbrNodes; + if (nd.getConstraint() == 7){ + ++nbrElems0; + } + } + nbrElems = nbrElems0/2; - if(nb) paraHelper.write_header(nb,1); - else paraHelper.write_header(nb,0); + if(nbrNodes) paraHelper.write_header(nbrNodes,nbrElems); + else paraHelper.write_header(nbrNodes,0); UnitsConverter unit; unit.setInUnits(code_unit_system); unit.setOutUnits(code_unit_system); unit.computeConversions(); - paraHelper.startDofList(); + std::vector<UInt> considered_indices; + std::vector<UInt> offsets; + UInt accumulated_offset = 0; + paraHelper.startDofList(); typename Cont::iterator itNodes = cNodes.getIterator(); + std::vector<UInt> constraints; + + for (RefNode nd = itNodes.getFirst(); !itNodes.end(); nd = itNodes.getNext()) { + RefNode nextNode = nd; + RefNode nextNode0= nd; + UInt cnst = nd.getConstraint(); + UInt idx = nd.getIndex(); + bool from_while_loop (false); + UInt offset = 1; + if( (cnst == 7) && (std::find(considered_indices.begin(), considered_indices.end(), idx) == considered_indices.end())){ + considered_indices.push_back(idx); + Real X[3] = {0,0,0}; + for (UInt i = 0; i < Dim; ++i) + X[i] = nd.position(i)*unit.getConversion<Length>(); + for (UInt i = 0; i < 3; ++i) + paraHelper.pushReal(X[i]); + constraints.push_back(cnst); + UInt count = 0; + while (from_while_loop == false){ + ++count; + if(count > 1e+8) + LM_FATAL("stop due to infinite while loop"); + + UInt NBNeigh = nextNode.getNbrOfNeighs(); + for (UInt i=0; i<NBNeigh; ++i){ + idx = nextNode.getNeighborNodeIndex(i); + nextNode0 = itNodes.getByIndex(idx); + cnst= nextNode0.getConstraint(); + + if(std::find(considered_indices.begin(), considered_indices.end(), idx) == considered_indices.end()){ + ++offset; + considered_indices.push_back(idx); + nextNode = nextNode0; + Real X[3] = {0,0,0}; + for (UInt j = 0; j < Dim; ++j) + X[j] = nextNode.position(j)*unit.getConversion<Length>(); + for (UInt j = 0; j < 3; ++j) + paraHelper.pushReal(X[j]); + constraints.push_back(cnst); + if(cnst == 7){ + from_while_loop = true; + accumulated_offset += offset; + break; + } + } + } + } + } + if(from_while_loop){ + offsets.push_back(accumulated_offset); + from_while_loop = false; + } + } + for (RefNode nd = itNodes.getFirst();!itNodes.end();nd = itNodes.getNext()) { Real X[3] = {0,0,0}; - for (UInt i = 0; i < Dim; ++i) - X[i] = nd.position(i)*unit.getConversion<Length>(); - - for (UInt i = 0; i < 3; ++i) - paraHelper.pushReal(X[i]); + for (UInt i = 0; i < Dim; ++i) + X[i] = nd.position(i)*unit.getConversion<Length>(); + for (UInt i = 0; i < 3; ++i) + paraHelper.pushReal(X[i]); } - paraHelper.endDofList(); - paraHelper.startCellsConnectivityList(); - for (UInt i=0;i < nb;++i) - { - paraHelper.pushInteger(i); - } + - paraHelper.endCellsConnectivityList(); - paraHelper.startCellsoffsetsList(); + if(offsets.size() != nbrElems) + LM_FATAL("problem: number of elements:"<<nbrElems<< + " but offset size:"<<offsets.size()); - paraHelper.pushInteger(nb); + paraHelper.startCellsConnectivityList(); + for(UInt i=0; i<nbrNodes; ++i){ + paraHelper.pushInteger(i); + } + paraHelper.endCellsConnectivityList(); + paraHelper.startCellsoffsetsList(); + for (UInt i=0; i<nbrElems; ++i){ + paraHelper.pushInteger(offsets[i]); + } paraHelper.endCellsoffsetsList(); - paraHelper.startCellstypesList(); - if(nb){ - paraHelper.pushInteger(2); + paraHelper.startCellstypesList(); + if(nbrNodes){ + for (UInt i=0; i<nbrElems; ++i){ + paraHelper.pushInteger(4); + } } - paraHelper.endCellstypesList(); - paraHelper.startPointDataList(); - if (force_serie){ paraHelper.startData("force",3); for (RefNode nd = itNodes.getFirst();!itNodes.end();nd = itNodes.getNext()) { double fx=0,fy=0,fz=0; fx = nd.force(0); if (Dim > 1) fy = nd.force(1); if (Dim == 3) fz = nd.force(2); paraHelper.pushReal(fx); paraHelper.pushReal(fy); paraHelper.pushReal(fz); } paraHelper.endData(); } if (stress_serie){ paraHelper.startData("stress",6); for (RefNode nd = itNodes.getFirst();!itNodes.end();nd = itNodes.getNext()) { Real x = nd.stress(0); Real y = nd.stress(1); Real z = nd.stress(2); paraHelper.pushReal(x); paraHelper.pushReal(y); paraHelper.pushReal(z); x = nd.stress(3); y = nd.stress(4); z = nd.stress(5); paraHelper.pushReal(x); paraHelper.pushReal(y); paraHelper.pushReal(z); } paraHelper.endData(); } paraHelper.startData("kind",1); + UInt count = 0; for (RefNode nd = itNodes.getFirst();!itNodes.end();nd = itNodes.getNext()) { - paraHelper.pushReal(0); + paraHelper.pushInteger(constraints[count]); + ++count; } paraHelper.endData(); paraHelper.endPointDataList(); paraHelper.write_conclusion(); file.close(); } /* -------------------------------------------------------------------------- */ DECLARE_DUMPER_REF(DumperParaview,LIST_DD_MODEL) __END_LIBMULTISCALE__