diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f063596..e72b7be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,107 +1,109 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # # @date Thu Nov 24 08:24:43 2011 # # @brief main iohelper configuration # # @section LICENSE # # Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu 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. # # Akantu 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 Akantu. If not, see . # #=============================================================================== #=============================================================================== # List of source files #=============================================================================== set(IOHELPER_COMMON_SRC dumper_lammps.cc dumper.cc dumper_restart.cc # src/reader_C_wrapper.cpp # src/reader.cpp # src/dumper_C_wrapper.cpp dumper_paraview.cc + dumper_text.cc paraview_helper.cc # src/reader_restart.cpp ) set(IOHELPER_COMMON_HEADERS field_inline_impl.cc dumper_restart.hh field_interface.hh visitor.hh field.hh container_array.hh dumper_paraview.hh + dumper_text.hh paraview_helper.tcc iohelper_common.hh io_helper.hh dumper.hh file_manager.hh paraview_helper.hh dumper_C_wrapper.h base64.hh # src/reader_C_wrapper.h # src/reader.hh dumper_lammps.hh base64_reader.hh # src/reader_restart.hh ) #=============================================================================== # Library creation rule #=============================================================================== include_directories( ${IOHELPER_SOURCE_DIR}/src ) add_library(iohelper ${IOHELPER_COMMON_SRC}) # link library with other libraries target_link_libraries (iohelper ${IOHELPER_EXTERNAL_LIBS}) set_target_properties(iohelper PROPERTIES PUBLIC_HEADER "${IOHELPER_COMMON_HEADERS}") export(TARGETS iohelper FILE "${CMAKE_BINARY_DIR}/IOHelperLibraryDepends.cmake") export(PACKAGE IOHelper) #=============================================================================== # Install rules #=============================================================================== # Tweak for when IOHelper is a subproject if(NOT IOHELPER_TARGETS_EXPORT) set(IOHELPER_TARGETS_EXPORT IOHelperLibraryDepends) endif() install(TARGETS iohelper EXPORT ${IOHELPER_TARGETS_EXPORT} LIBRARY DESTINATION lib COMPONENT shlib PUBLIC_HEADER DESTINATION include/iohelper COMPONENT dev ) # Install the export set for use with the install-tree if("${IOHELPER_TARGETS_EXPORT}" STREQUAL "IOHelperLibraryDepends") install(EXPORT IOHelperLibraryDepends DESTINATION lib/iohelper COMPONENT dev) endif() set(IOHELPER_INCLUDE_DIRS ${IOHelper_SOURCE_DIR}/src CACHE INTERNAL "Internal include directorie to link with IOHelper as a subproject") diff --git a/src/field_inline_impl.cc b/src/dumper_text.cc similarity index 57% copy from src/field_inline_impl.cc copy to src/dumper_text.cc index a06ce45..23d9efe 100644 --- a/src/field_inline_impl.cc +++ b/src/dumper_text.cc @@ -1,57 +1,66 @@ /** - * @file field_inline_impl.cc + * @file dumper_text.cc + * @author David Kammer + * @date Tue May 14 11:11:59 2013 * - * @author Till Junge - * @author Guillaume Anciaux - * - * @date Wed Oct 31 21:45:06 2012 - * - * @brief inline implementation of dumper visitor + * @brief implementation for text dumper * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu 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. * * Akantu 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 Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ +#include +#include "dumper_text.hh" /* -------------------------------------------------------------------------- */ -#include "paraview_helper.hh" -#include "dumper_lammps.hh" +#if defined(__INTEL_COMPILER) +/// remark #981: operands are evaluated in unspecified order +#pragma warning ( disable : 981 ) +#endif //defined(__INTEL_COMPILER) -#ifndef __IOHELPER_FIELD_INLINE_IMPL_CC__ -#define __IOHELPER_FIELD_INLINE_IMPL_CC__ +__BEGIN_IOHELPER__ /* -------------------------------------------------------------------------- */ -__BEGIN_IOHELPER__ +void DumperText::dump(__attribute__((unused)) const std::string & basename){ -template -inline void Field::accept(Visitor & v){ - if (ParaviewHelper * ptr_ph = dynamic_cast(&v)){ - ptr_ph->visit(*this); - } else if (iohelper::DumperLammps * ptr_dlb = dynamic_cast*>(&v)) { - ptr_dlb->visit(*this); - } else if (DumperLammps * ptr_dla = dynamic_cast*>(&v)){ - ptr_dla->visit(*this); + /* nodal data */ + std::map::iterator it = per_node_data.begin(); + std::map::iterator end = per_node_data.end(); + + for (; it != end ; ++it) { + (*it).second->accept(*this); } -} + /* element data */ + it = per_element_data.begin(); + end = per_element_data.end(); + for (; it != end ; ++it) { + (*it).second->accept(*this); + } + + this->incDumpStep(); +} +/* -------------------------------------------------------------------------- */ __END_IOHELPER__ + /* -------------------------------------------------------------------------- */ -#endif /* __IOHELPER_FIELD_INLINE_IMPL_CC__ */ + + diff --git a/src/dumper_text.hh b/src/dumper_text.hh new file mode 100644 index 0000000..5cd406b --- /dev/null +++ b/src/dumper_text.hh @@ -0,0 +1,107 @@ + /** + * @file dumper_text.hh + * @author David Kammer + * @date Tue May 14 11:11:21 2013 + * + * @brief header for dumper text + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu 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. + * + * Akantu 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 Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#ifndef __IOHLPER_DUMPER_TEXT_H__ +#define __IOHLPER_DUMPER_TEXT_H__ +/* -------------------------------------------------------------------------- */ +#include +#include +#include +#include "dumper.hh" +#include "file_manager.hh" +/* -------------------------------------------------------------------------- */ + +__BEGIN_IOHELPER__ + +/** Class DumperText + * Implementation of a dumper to text file + */ + +class DumperText : public Dumper, public Visitor { + + /* ------------------------------------------------------------------------ */ + /* Constructors/Destructors */ + /* ------------------------------------------------------------------------ */ + +public: + + DumperText(std::string prefix = "./") : Dumper(prefix) {}; + ~DumperText() {}; + + /* ------------------------------------------------------------------------ */ + /* Methods */ + /* ------------------------------------------------------------------------ */ + + void dump(const std::string & name); + void setEmbeddedValue(__attribute__((unused)) const std::string & name, + __attribute__((unused)) int value) {}; + + //! visitor system + template void visit(T & visited); + +private: + + /* ------------------------------------------------------------------------ */ + /* Class Members */ + /* ------------------------------------------------------------------------ */ + +private: +}; + +/* -------------------------------------------------------------------------- */ +template +void DumperText::visit(T & visited){ + File file; + + /* node coordinates */ + std::stringstream filename; + filename << this->getFullName(visited.getName()); + filename << ".out"; + + file.open(filename.str(),std::fstream::out); + + typename T::iterator it = visited.begin(); + typename T::iterator end = visited.end(); + + UInt dim = visited.getDim(); + + for (; it != end; ++it) { + for (UInt i=0; i * @author Guillaume Anciaux * * @date Wed Oct 31 21:45:06 2012 * * @brief inline implementation of dumper visitor * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu 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. * * Akantu 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 Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "paraview_helper.hh" #include "dumper_lammps.hh" +#include "dumper_text.hh" #ifndef __IOHELPER_FIELD_INLINE_IMPL_CC__ #define __IOHELPER_FIELD_INLINE_IMPL_CC__ /* -------------------------------------------------------------------------- */ __BEGIN_IOHELPER__ template inline void Field::accept(Visitor & v){ if (ParaviewHelper * ptr_ph = dynamic_cast(&v)){ ptr_ph->visit(*this); } else if (iohelper::DumperLammps * ptr_dlb = dynamic_cast*>(&v)) { ptr_dlb->visit(*this); } else if (DumperLammps * ptr_dla = dynamic_cast*>(&v)){ ptr_dla->visit(*this); + } else if (DumperText * ptr_txt = dynamic_cast(&v)){ + ptr_txt->visit(*this); } } __END_IOHELPER__ /* -------------------------------------------------------------------------- */ #endif /* __IOHELPER_FIELD_INLINE_IMPL_CC__ */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9e407e4..4cc6042 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,41 +1,49 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # # @date Thu Oct 11 12:43:10 2012 # # @brief configuration file for tests # # @section LICENSE # # Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu 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. # # Akantu 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 Akantu. If not, see . # #=============================================================================== SET(test_paraview_dumper_SRC mesh_io_msh.cc test_paraview_dumper.cc ) +SET(test_text_dumper_SRC + mesh_io_msh.cc + test_text_dumper.cc + ) + add_executable(test_paraview_dumper ${test_paraview_dumper_SRC}) +add_executable(test_text_dumper ${test_text_dumper_SRC}) target_link_libraries(test_paraview_dumper iohelper) +target_link_libraries(test_text_dumper iohelper) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/cube.msh DESTINATION .) add_test(test_paraview_dumper test_paraview_dumper cube.msh 3) +add_test(test_text_dumper test_text_dumper cube.msh 3) diff --git a/test/test_paraview_dumper.cc b/test/test_paraview_dumper.cc index 03655b9..48c49be 100644 --- a/test/test_paraview_dumper.cc +++ b/test/test_paraview_dumper.cc @@ -1,61 +1,62 @@ /** * @file test_paraview_dumper.cc * * @author Guillaume Anciaux * * @date Thu Oct 11 12:43:10 2012 * * @brief paraview dump test * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu 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. * * Akantu 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 Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ -#include "dumper_paraview.hh" +#include "../src/dumper_paraview.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char ** argv){ if (argc != 3){ - FATAL("Usage: program meshfile dimension"); + std::cerr << "Usage: program meshfile dimension" << std::endl; + return EXIT_FAILURE; } std::string meshfilename(argv[1]); int dim = atoi(argv[2]); std::vector nodes; std::vector connectivities; int nb_elements; MeshIOMSH meshio; meshio.read(meshfilename,dim,MeshIOMSH::_msh_tetrahedron_4,nodes,connectivities); nb_elements = connectivities.size()/meshio._msh_nodes_per_elem[MeshIOMSH::_msh_tetrahedron_4]; iohelper::DumperParaview dumper; // dumper.setMode(iohelper::TEXT); dumper.setPoints(&nodes[0], dim, nodes.size()/dim, "coordinates2"); dumper.setConnectivity(&connectivities[0],iohelper::TETRA1, nb_elements, iohelper::C_MODE); dumper.addNodeDataField("test",&nodes[0],dim, nodes.size()/dim); dumper.setPrefix("./"); dumper.setVTUSubDirectory("test_tetra4-VTUs"); dumper.init(); dumper.dump("test_tetra4"); } diff --git a/test/test_paraview_dumper.cc b/test/test_text_dumper.cc similarity index 82% copy from test/test_paraview_dumper.cc copy to test/test_text_dumper.cc index 03655b9..a9621ba 100644 --- a/test/test_paraview_dumper.cc +++ b/test/test_text_dumper.cc @@ -1,61 +1,60 @@ /** - * @file test_paraview_dumper.cc + * @file test_text_dumper.cc + * @author David Kammer + * @date Tue May 14 13:24:37 2013 * - * @author Guillaume Anciaux - * - * @date Thu Oct 11 12:43:10 2012 - * - * @brief paraview dump test + * @brief text dumper test * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu 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. * * Akantu 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 Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ -#include "dumper_paraview.hh" +#include "../src/dumper_text.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char ** argv){ if (argc != 3){ - FATAL("Usage: program meshfile dimension"); + std::cerr << "Usage: program meshfile dimension" << std::endl; + return EXIT_FAILURE; } std::string meshfilename(argv[1]); int dim = atoi(argv[2]); std::vector nodes; std::vector connectivities; int nb_elements; MeshIOMSH meshio; meshio.read(meshfilename,dim,MeshIOMSH::_msh_tetrahedron_4,nodes,connectivities); nb_elements = connectivities.size()/meshio._msh_nodes_per_elem[MeshIOMSH::_msh_tetrahedron_4]; - iohelper::DumperParaview dumper; + iohelper::DumperText dumper; // dumper.setMode(iohelper::TEXT); dumper.setPoints(&nodes[0], dim, nodes.size()/dim, "coordinates2"); dumper.setConnectivity(&connectivities[0],iohelper::TETRA1, nb_elements, iohelper::C_MODE); dumper.addNodeDataField("test",&nodes[0],dim, nodes.size()/dim); dumper.setPrefix("./"); - dumper.setVTUSubDirectory("test_tetra4-VTUs"); + // dumper.setVTUSubDirectory("test_tetra4-VTUs"); dumper.init(); - dumper.dump("test_tetra4"); + dumper.dump("test_text_tetra4"); }