From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 24 Jun 2019 14:43:36 +0200 Subject: Initialize at openlb-1-3 --- src/particles/particle3D.hh | 537 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 537 insertions(+) create mode 100755 src/particles/particle3D.hh (limited to 'src/particles/particle3D.hh') diff --git a/src/particles/particle3D.hh b/src/particles/particle3D.hh new file mode 100755 index 0000000..03efa57 --- /dev/null +++ b/src/particles/particle3D.hh @@ -0,0 +1,537 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2016 Thomas Henn + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef PARTICLE_3D_HH +#define PARTICLE_3D_HH + +#include +#include +#include +#include +#include +#include + +#include "particle3D.h" + +namespace olb { + +template +Particle3D::Particle3D() + : _pos(3, 0.), + _vel(3, 0.), + _force(3, 0.), + _mas(0), + _rad(0), + _cuboid(0), + _id(0), + _active(false), + _storeForce(3, 0.) +{ +} + +template +Particle3D::Particle3D(std::vector pos, T mas, T rad, int id) + : _pos(pos), + _vel(3, 0.), + _force(3, 0.), + _mas(mas), + _rad(rad), + _cuboid(0), + _id(id), + _active(true), + _storeForce(3, 0.) +{ + _invMas = 1. / _mas; + // RK4 +// _positions = std::vector > (4, std::vector (3, T() )); +// _velocities = std::vector > (4, std::vector (3, T() )); +// _forces = std::vector > (4, std::vector (3, T() )); +} + +template +Particle3D::Particle3D(const Particle3D& p) + : _pos(p._pos), + _vel(p._vel), + _force(p._force), + _mas(p._mas), + _rad(p._rad), + _cuboid(p._cuboid), + _id(p._id), + _active(p._active), + _storeForce(p._storeForce) +{ + _invMas = 1. / _mas; + // RK4 +// _positions = std::vector > (4, std::vector (3, T() )); +// _velocities = std::vector > (4, std::vector (3, T() )); +// _forces = std::vector > (4, std::vector (3, T() )); +} + +template +Particle3D::Particle3D(std::vector pos, std::vector vel, T mas, T rad, int id) + : _pos(pos), + _vel(vel), + _force(12, 0.), + _mas(mas), + _rad(rad), + _cuboid(0), + _id(id), + _active(true), + _storeForce(3, 0.) +{ + _vel.resize(12, 0.); + // RK4 +// _positions = std::vector > (4, std::vector (3, T() )); +// _velocities = std::vector > (4, std::vector (3, T() )); +// _forces = std::vector > (4, std::vector (3, T() )); +} + +template +inline void Particle3D::addForce(std::vector& force) +{ + for (int i = 0; i < 3; i++) { + _force[i] += force[i]; + } +} +// set and get force +template +inline void Particle3D::setForce(std::vector& force) +{ + _force = force; +} +template +inline void Particle3D::resetForce() +{ + for (int i = 0; i < 3; i++) { + _force[i] = 0.; + } +} + +// set and get storedForce +template +inline void Particle3D::setStoreForce(std::vector& storeForce) +{ + for (int i = 0; i < 3; i++) { + _storeForce[i] = storeForce[i]; + } +} + +template +inline void Particle3D::resetStoreForce() +{ + for (int i = 0; i < 3; i++) { + _storeForce[i] = T(0); + } +} + +template +void Particle3D::serialize(T serial[]) +{ + for (int i = 0; i < 3; i++) { + serial[i] = _pos[i]; + serial[i + 3] = _vel[i]; + serial[i + 6] = _force[i]; + } + serial[9] = _mas; + serial[10] = _rad; + serial[11] = _cuboid; + serial[12] = _active; + serial[13] = _id; + + for (int i = 0; i < 3; i++) { + serial[i + 14] = _storeForce[i]; + } + + // for (int i = 0; i < 17; i++) { + // cout << "serialize " << i << ": " << serial[i] << " tn: " << typeid(serial[i]).name() << endl; + // } +} + +template +void Particle3D::unserialize(T* data) +{ + for (int i = 0; i < 3; i++) { + _pos[i] = data[i]; + _vel[i] = data[i + 3]; + _force[i] = data[i + 6]; + } + _mas = data[9]; + _rad = data[10]; + _cuboid = int(data[11]); + _active = data[12]; + _invMas = 1. / _mas; + _id = data[13]; + + for (int i = 0; i < 3; i++) { + _storeForce[i] = data[i + 14]; + } + + // for (int i = 0; i < 17; i++) { + // cout << "unserialize " << i << ": " << data[i] << " tn: " << typeid(data[i]).name() << endl; + // } +} + +template +void Particle3D::print() +{ + std::cout << "Pos " << _pos[0] << " " << _pos[1] << " " << _pos[2] << " " << "Vel " + << _vel[0] << " " << _vel[1] << " " << _vel[2] << " " << _cuboid + << std::endl; +} + +template +void Particle3D::printDeep(std::string message) +{ + std::cout << message << " Particle ID " << this->getID() + << " rad " << this->getRad() + << " mass " << this->getMass() + << " invMass " << this->getInvMass() + << " force " << this->getForce()[0] << " " << this->getForce()[1] << " " << this->getForce()[2] + << " storeForce " << this->getStoreForce()[0] << " " << this->getStoreForce()[1] << " " << this->getStoreForce()[2] + << " "; + this->print(); +} + +template +ElParticle3D::ElParticle3D() + : Particle3D(), + _charge(1.) +{ +} + +template +ElParticle3D::ElParticle3D(std::vector pos, T mas, T rad, T charge) + : Particle3D(pos, mas, rad), + _charge(charge) +{ +} + +template +ElParticle3D::ElParticle3D(std::vector pos, std::vector vel, T mas, + T rad, T charge) + : Particle3D(pos, vel, mas, rad), + _charge(charge) +{ +} + +template +ElParticle3D::ElParticle3D(const ElParticle3D& p) + : Particle3D(p), + _charge(p._charge) +{ +} + +template +void ElParticle3D::serialize(T serial[]) +{ + serial[0] = this->_pos[0]; + serial[1] = this->_pos[1]; + serial[2] = this->_pos[2]; + serial[3] = this->_vel[0]; + serial[4] = this->_vel[1]; + serial[5] = this->_vel[2]; + serial[6] = this->_rad; + serial[7] = this->_mas; + serial[8] = (double) this->_active; + serial[9] = _charge; +} + +template +void ElParticle3D::unserialize(T* data) +{ + this->_pos[0] = data[0]; + this->_pos[1] = data[1]; + this->_pos[2] = data[2]; + this->_vel[0] = data[3]; + this->_vel[1] = data[4]; + this->_vel[2] = data[5]; + this->_rad = data[6]; + this->_mas = data[7]; + this->_active = (bool) data[8]; + _charge = data[9]; +} + +template +AggParticle3D::AggParticle3D() + : Particle3D::Particle3D() +{ + _aggl = false; +} + +template +AggParticle3D::AggParticle3D(std::vector pos, T mas, T rad) + : Particle3D::Particle3D(pos, mas, rad) +{ + _aggl = false; +} + +template +AggParticle3D::AggParticle3D(const Particle3D& p) + : Particle3D::Particle3D(p) +{ + _aggl = false; +} + +template +AggParticle3D::AggParticle3D(std::vector pos, std::vector vel, T mas, + T rad) + : Particle3D::Particle3D(pos, vel, mas, rad) +{ + _aggl = false; +} + +template +void AggParticle3D::serialize(T serial[]) +{ + for (int i = 0; i < 3; i++) { + serial[i] = this->_pos[i]; + serial[i + 3] = this->_vel[i]; + serial[i + 6] = this->_force[i]; + } + serial[9] = this->_mas; + serial[10] = this->_rad; + serial[11] = this->_cuboid; + serial[12] = (double) this->_active; + serial[13] = (double) _aggl; +} + +template +void AggParticle3D::unserialize(T* data) +{ + for (int i = 0; i < 3; i++) { + this->_pos[i] = data[i]; + this->_vel[i] = data[i + 3]; + this->_force[i] = data[i + 6]; + } + this->_mas = data[9]; + this->_rad = data[10]; + this->_cuboid = int(data[11]); + this->_active = (bool) data[12]; + _aggl = (bool) data[13]; +} + +template +RotatingParticle3D::RotatingParticle3D() + : Particle3D::Particle3D(), _aVel(3, T()), _torque(3, T()) +{ +} + +template +RotatingParticle3D::RotatingParticle3D(std::vector pos, T mas, T rad) + : Particle3D::Particle3D(pos, mas, rad), _aVel(3, T()), _torque(3, T()) +{ +} + +template +RotatingParticle3D::RotatingParticle3D(const RotatingParticle3D& p) + : Particle3D::Particle3D(p), _aVel(p.getAVel()), _torque(p._torque) +{ +} + +template +RotatingParticle3D::RotatingParticle3D(std::vector pos, std::vector vel, T mas, + T rad) + : Particle3D::Particle3D(pos, vel, mas, rad), _aVel(3, T()), _torque(3, T()) +{ +} + + +template +void RotatingParticle3D::serialize(T serial[]) +{ + for (int i = 0; i < 3; i++) { + serial[i] = this->_pos[i]; + serial[i + 3] = this->_vel[i]; + serial[i + 6] = this->_force[i]; + } + serial[9] = this->_mas; + serial[10] = this->_rad; + serial[11] = this->_cuboid; + serial[12] = (double) this->_active; + serial[13] = (double) _aVel[0]; + serial[14] = (double) _aVel[1]; + serial[15] = (double) _aVel[2]; + serial[16] = (double) _torque[0]; + serial[17] = (double) _torque[1]; + serial[18] = (double) _torque[2]; +} + +template +void RotatingParticle3D::unserialize(T* data) +{ + for (int i = 0; i < 3; i++) { + this->_pos[i] = data[i]; + this->_vel[i] = data[i + 3]; + this->_force[i] = data[i + 6]; + } + this->_mas = data[9]; + this->_rad = data[10]; + this->_cuboid = int(data[11]); + this->_active = (bool) data[12]; + _aVel[0] = (bool) data[13]; + _aVel[1] = (bool) data[14]; + _aVel[2] = (bool) data[15]; + _torque[0] = (bool) data[16]; + _torque[1] = (bool) data[17]; + _torque[2] = (bool) data[18]; +} + + +template +MagneticParticle3D::MagneticParticle3D() + : Particle3D::Particle3D(), _dMoment(3, T()), _aVel(3, T()), _torque(3, T()), _magnetisation(T()) +{ + +} + +template +MagneticParticle3D::MagneticParticle3D(const MagneticParticle3D& p) + : Particle3D::Particle3D(p), _dMoment(p._dMoment), _aVel(p._aVel), _torque(p._torque), _magnetisation(p._magnetisation), _sActivity(p._sActivity) +{ +} + +template +MagneticParticle3D::MagneticParticle3D(std::vector pos, std::vector vel, T mas, + T rad, int id) + : Particle3D::Particle3D(pos, vel, mas, rad), _dMoment(3, T()), _aVel(3, T()), _torque(3, T()), _magnetisation(T()) +{ +} + +template +MagneticParticle3D::MagneticParticle3D(std::vector pos, std::vector vel, T mas, T rad, int id, + std::vector dMoment, std::vector aVel, std::vector torque, T magnetisation) + : Particle3D::Particle3D(pos, vel, mas, rad, id), + _dMoment(dMoment), _aVel(aVel), _torque(torque), _magnetisation(magnetisation) +{ +} + +template +MagneticParticle3D::MagneticParticle3D(std::vector pos, std::vector vel, T mas, T rad, int id, + std::vector dMoment, std::vector aVel, std::vector torque, T magnetisation, int sActivity) + : Particle3D::Particle3D(pos, vel, mas, rad, id), + _dMoment(dMoment), _aVel(aVel), _torque(torque), _magnetisation(magnetisation), _sActivity(sActivity) +{ +} + +template +inline void MagneticParticle3D::resetTorque() +{ + for (int i = 0; i < 3; i++) { + _torque[i] = 0.; + } +} + +template +inline void MagneticParticle3D::setMoment(std::vector moment) +{ + _dMoment = moment; +// std::cout<< "Setting moment: "<< _dMoment[0] << " " << _dMoment[1] << " " <<_dMoment[2] << std::endl; +} + +template +inline void MagneticParticle3D::setAVel(std::vector aVel) +{ + _aVel = aVel; +} + +template +inline void MagneticParticle3D::setTorque(std::vector torque) +{ + _torque = torque; + //std::cout<< "Setting torque: "<< _torque[0] << " " << _torque[1] << " " <<_torque[2] << std::endl; +} + +template +inline void MagneticParticle3D::setMagnetisation(T magnetisation) +{ + _magnetisation = magnetisation; + //std::cout<< "Setting magnetisation: "<< _magnetisation << std::endl; +} + +template +inline void MagneticParticle3D::setSActivity(int sActivity) +{ + _sActivity = sActivity; +} + +template +inline void MagneticParticle3D::setAggloItr(typename std::deque*>>::iterator aggloItr) +{ + _aggloItr = aggloItr; +} + + + +template +void MagneticParticle3D::serialize(T serial[]) +{ + + for (int i = 0; i < 3; i++) { + serial[i] = this->_pos[i]; + serial[i + 3] = this->_vel[i]; + serial[i + 6] = this->_force[i]; + } + serial[9] = this->_mas; + serial[10] = this->_rad; + serial[11] = (double) this->_cuboid; + serial[12] = (double) this->_active; + serial[13] = (double) this->_id; + for (int i = 0; i < 3; i++) { + serial[i + 14] = this->_storeForce[i]; + serial[i + 17] = _dMoment[i]; + serial[i + 20] = _aVel[i]; + serial[i + 23] = _torque[i]; + } + serial[26] = _magnetisation; + serial[27] = (double) _sActivity; + +} + +template +void MagneticParticle3D::unserialize(T* data) +{ + + for (int i = 0; i < 3; i++) { + this->_pos[i] = data[i]; + this->_vel[i] = data[i + 3]; + this->_force[i] = data[i + 6]; + } + this->_mas = data[9]; + this->_rad = data[10]; + this->_cuboid = (int) data[11]; + this->_active = (bool) data[12]; + this->_id = (int) data[13]; + for (int i = 0; i < 3; i++) { + this->_storeForce[i] = data[i + 14]; + _dMoment[i] = data[i + 17]; + _aVel[i] = data[i + 20]; + _torque[i] = data[i + 23]; + } + _magnetisation = data[26]; + _sActivity = (int) data[27]; + +} + +} + +#endif /* PARTICLE_3D_HH */ -- cgit v1.2.3