Page MenuHomec4science

dumper_lammps.cpp
No OneTemporary

File Metadata

Created
Wed, Jul 17, 23:14

dumper_lammps.cpp

/**
* @file dumper_lammps.cpp
* @author Till Junge <junge@lsmspc42.epfl.ch>
* @date Wed Nov 24 17:27:26 2010
*
* @brief *
* @section LICENSE
*
* <insert lisence here>
*
*/
/* -------------------------------------------------------------------------- */
#include <sstream>
using namespace std;
#include "common.h"
#include "dumper_lammps.h"
/* -------------------------------------------------------------------------- */
__BEGIN_IOHELPER__
DumperLammps::DumperLammps()
:Dumper() {
elem_type = POINT_SET;
}
/* -------------------------------------------------------------------------- */
DumperLammps::DumperLammps(std::string _prefix, string _base_name)
:Dumper() {
elem_type = POINT_SET;
this->prefix = _prefix;
this->base_name = _base_name;
}
/* -------------------------------------------------------------------------- */
void DumperLammps::Dump() {
this->DumpHead();
this->DumpAdd();
this->DumpFinalize();
}
/* -------------------------------------------------------------------------- */
void DumperLammps::DumpHead() {
this->curr_nb_atom = 0;
std::stringstream filename;
filename << this->prefix << "/" << this->base_name << "_pvf";
filename.width(5);
filename.fill('0');
filename << this->dump_step;
char affe[512]; strcpy(affe,filename.str().c_str());
this->lammps_dump_file.open(filename.str().c_str(), std::fstream::in | std::fstream::out | std::fstream::trunc);
if (!this->lammps_dump_file.good()) {
std::cerr << "hach" << std::endl;
if (this->lammps_dump_file.rdstate() & std::fstream::eofbit) std::cerr << " 1 " << std::endl;
if (this->lammps_dump_file.rdstate() & std::fstream::failbit) std::cerr << " 2 " << std::endl;
if (this->lammps_dump_file.rdstate() & std::fstream::badbit) std::cerr << " 3 " << std::endl;
if (this->lammps_dump_file.rdstate() & std::fstream::goodbit) std::cerr << " 4 " << std::endl;
exit(-1);
}
this->lammps_dump_file << "LAMMPS data file" << std::endl << std::endl << std::endl;
this->nb_atom_position = lammps_dump_file.tellp();
this->lammps_dump_file << " atoms" << std::endl << std::endl;
this->lammps_dump_file << " 1 atom types" << std::endl << std::endl;
this->lammps_dump_file << "Atoms" << std::endl << std::endl;
this->lammps_dump_file.setf(std::ios::scientific, std::ios::floatfield);
this->lammps_dump_file.precision(20);
}
/* -------------------------------------------------------------------------- */
void DumperLammps::DumpAdd(int grain_id, double * points, int dimension, int nb, const char * name) {
if (points != NULL) {
this -> SetPoints(points, dimension, nb*dimension, name);
}
unsigned int nb_atoms = this->position->getNbDof() / this->position->getDim();
double * atom_ptr = this->position->getData();
unsigned int dim = this->position->getDim();
for (unsigned int i = 0; i < nb_atoms; ++i) {
this->lammps_dump_file << this->curr_nb_atom + i<< " " << grain_id << " " << atom_ptr[dim * i] << " " << atom_ptr[dim * i + 1] << " " << atom_ptr[dim * i + 2] << std::endl;
}
this->curr_nb_atom += nb_atoms;
}
/* -------------------------------------------------------------------------- */
void DumperLammps::DumpFinalize(){
this->lammps_dump_file.seekp(this->nb_atom_position);
this->lammps_dump_file << curr_nb_atom;
this->lammps_dump_file.close();
}
/* -------------------------------------------------------------------------- */
__END_IOHELPER__

Event Timeline