Skip to content
Snippets Groups Projects
Commit 2a214b73 authored by kutscher's avatar kutscher
Browse files

add coprocessor and wrapper for LIGGGHTS

parent a5891e8d
No related branches found
No related tags found
2 merge requests!171Newest Update,!83Fix MPICommunicator
...@@ -4,90 +4,96 @@ ...@@ -4,90 +4,96 @@
#include "VirtualFluids.h" #include "VirtualFluids.h"
#include "lammps.h" //#include "lammps.h"
#include "input.h" //#include "input.h"
#include "atom.h" //#include "atom.h"
#include "modify.h" //#include "modify.h"
#include "fix_lb_coupling_onetoone.h" //#include "fix_lb_coupling_onetoone.h"
#include "LiggghtsCouplingCoProcessor.h"
#include "LiggghtsCouplingWrapper.h"
#include "LiggghtsCoProcessor.h"
using namespace std; using namespace std;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
LAMMPS_NS::LAMMPS *lmp; SPtr<Communicator> comm = MPICommunicator::getInstance();
// custom argument vector for LAMMPS library LiggghtsCouplingWrapper wrapper(argv, (MPI_Comm)comm->getNativeCommunicator());
const char *lmpargv[] {"liblammps", "-log", "none"};
int lmpargc = sizeof(lmpargv)/sizeof(const char *); //LAMMPS_NS::LAMMPS *lmp;
// // custom argument vector for LAMMPS library
// explicitly initialize MPI // const char *lmpargv[] {"liblammps", "-log", "none"};
MPI_Init(&argc, &argv); // int lmpargc = sizeof(lmpargv)/sizeof(const char *);
// create LAMMPS instance // // explicitly initialize MPI
lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD); // MPI_Init(&argc, &argv);
lmp->input->file("in.lbdem");
//lmp->input->one("run 1"); // // create LAMMPS instance
// lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD);
//# Try extracting a global value // lmp->input->file("in.lbdem");
// print("") // //lmp->input->one("run 1");
// print("Attempting to get the number of atoms in simulation") //
// numAtoms = lmp.extract_global("natoms", 0) // //# Try extracting a global value
// print("natoms =", numAtoms) // // print("")
// // print("Attempting to get the number of atoms in simulation")
// # Try extracting atom's positions // // numAtoms = lmp.extract_global("natoms", 0)
// print("") // // print("natoms =", numAtoms)
// print("Attempting to get the atom's positions")
// pos = lmp.extract_atom("x",3) // // # Try extracting atom's positions
// for k in range(0,numAtoms): // // print("")
// print("Pos[%i] = [%f, %f, %f]" % (k, pos[k][0], pos[k][1], pos[k][2])) // // print("Attempting to get the atom's positions")
// // pos = lmp.extract_atom("x",3)
LAMMPS_NS::FixLbCouplingOnetoone // // for k in range(0,numAtoms):
*couplingFix // // print("Pos[%i] = [%f, %f, %f]" % (k, pos[k][0], pos[k][1], pos[k][2]))
= dynamic_cast<LAMMPS_NS::FixLbCouplingOnetoone*>
(lmp->modify->find_fix_style("couple/lb/onetoone",0)); // LAMMPS_NS::FixLbCouplingOnetoone
// *couplingFix
cout << "test1\n"; // = dynamic_cast<LAMMPS_NS::FixLbCouplingOnetoone*>
// (lmp->modify->find_fix_style("couple/lb/onetoone",0));
//double **t_liggghts = couplingFix->get_torque_ptr();
cout << "test2\n"; // cout << "test1\n";
//
lmp->input->one("run 9 upto"); // //double **t_liggghts = couplingFix->get_torque_ptr();
// cout << "test2\n";
for (int step = 0; step < 10; step++)
{ // lmp->input->one("run 9 upto");
// for (int step = 0; step < 10; step++)
int numAtoms = lmp->atom->natoms; // {
//
//double** pos = (double**)lmp->atom->extract("x");
double** pos = lmp->atom->x; // int numAtoms = lmp->atom->natoms;
//double* forceX = lmp->atom->fx; // //double** pos = (double**)lmp->atom->extract("x");
// double** pos = lmp->atom->x;
for (int i = 0; i < numAtoms; i++) //
{ // //double* forceX = lmp->atom->fx;
double **f_liggghts = couplingFix->get_force_ptr();
double** force = lmp->atom->f; // for (int i = 0; i < numAtoms; i++)
cout << "Pos[" << i << "] = [" << pos[i][0] << ", " << pos[i][1] << ", " << pos[i][2] << "]\n"; // {
cout << "Force1[" << i << "] = [" << f_liggghts[i][0] << ", " << f_liggghts[i][1] << ", " << f_liggghts[i][2] << "]\n"; // double **f_liggghts = couplingFix->get_force_ptr();
f_liggghts[i][0] += 0; // double** force = lmp->atom->f;
f_liggghts[i][1] += 0; // cout << "Pos[" << i << "] = [" << pos[i][0] << ", " << pos[i][1] << ", " << pos[i][2] << "]\n";
f_liggghts[i][2] += 500; // cout << "Force1[" << i << "] = [" << f_liggghts[i][0] << ", " << f_liggghts[i][1] << ", " << f_liggghts[i][2] << "]\n";
cout << "Force2[" << i << "] = [" << force[i][0] << ", " << force[i][1] << ", " << force[i][2] << "]\n"; // f_liggghts[i][0] += 0;
} // f_liggghts[i][1] += 0;
// f_liggghts[i][2] += 500;
couplingFix->comm_force_torque(); // cout << "Force2[" << i << "] = [" << force[i][0] << ", " << force[i][1] << ", " << force[i][2] << "]\n";
// }
lmp->input->one("run 10000");
// couplingFix->comm_force_torque();
}
// lmp->input->one("run 10000");
// delete LAMMPS instance //
delete lmp; // }
// stop MPI environment // // delete LAMMPS instance
MPI_Finalize(); // delete lmp;
// // stop MPI environment
// MPI_Finalize();
return 0; return 0;
} }
This diff is collapsed.
#include "LiggghtsCouplingCoProcessor.h"
LiggghtsCouplingCoProcessor::LiggghtsCouplingCoProcessor()
{
}
LiggghtsCouplingCoProcessor::~LiggghtsCouplingCoProcessor()
{
}
void LiggghtsCouplingCoProcessor::process(double actualTimeStep)
{
}
\ No newline at end of file
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
// You should have received a copy of the GNU General Public License along // You should have received a copy of the GNU General Public License along
// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
// //
//! \file LiggghtsCoProcessor.h //! \file LiggghtsCouplingCoProcessor.h
//! \ingroup LiggghtsCoupling //! \ingroup LiggghtsCoupling
//! \author Konstantin Kutscher //! \author Konstantin Kutscher
//======================================================================================= //=======================================================================================
#ifndef LIGGGHTS_CO_PROCESSOR_H #ifndef LiggghtsCouplingCoProcessor_h
#define LIGGGHTS_CO_PROCESSOR_H #define LiggghtsCouplingCoProcessor_h
#include "CoProcessor.h" #include "CoProcessor.h"
...@@ -42,108 +42,15 @@ ...@@ -42,108 +42,15 @@
#include "modify.h" #include "modify.h"
#include "fix_lb_coupling_onetoone.h" #include "fix_lb_coupling_onetoone.h"
class LiggghtsCoProcessor : public CoProcessor class LiggghtsCouplingCoProcessor : public CoProcessor
{ {
public: public:
LiggghtsCoProcessor(); LiggghtsCouplingCoProcessor();
virtual ~LiggghtsCoProcessor(); virtual ~LiggghtsCouplingCoProcessor();
void process(double actualTimeStep) override;
}; };
#endif #endif
///*
// * Author: S. Peters
// * mail: peters@irmb.tu-bs.de
// */
//#ifndef DEM_CO_PROCESSOR_H
//#define DEM_CO_PROCESSOR_H
//
//#include <map>
//#include <memory>
//#include <vector>
//
//#include "Vector3D.h"
//
//#include "CoProcessor.h"
//#include "UbTuple.h"
//
//#include <pe/basic.h>
//
////#define TIMING
//
//#ifdef TIMING
//#include "UbTiming.h"
//#endif
//
//class PhysicsEngineGeometryAdapter;
//class PhysicsEngineSolverAdapter;
//class PePhysicsEngineSolverAdapter;
//class PhysicsEngineMaterialAdapter;
//class PePhysicsEngineGeometryAdapter;
//
//class UbScheduler;
//class Grid3D;
//class ForceCalculator;
//class Communicator;
//class MovableObjectInteractor;
//class Communicator;
//class BoundaryConditionsBlockVisitor;
//
//class DemCoProcessor : public CoProcessor
//{
//public:
// DemCoProcessor(std::shared_ptr<Grid3D> grid, std::shared_ptr<UbScheduler> s, std::shared_ptr<Communicator> comm,
// std::shared_ptr<ForceCalculator> forceCalculator,
// std::shared_ptr<PhysicsEngineSolverAdapter> physicsEngineSolver, double intermediatePeSteps = 1.0);
// virtual ~DemCoProcessor();
//
// void addInteractor(std::shared_ptr<MovableObjectInteractor> interactor,
// std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial,
// Vector3D initalVelocity = Vector3D(0.0, 0.0, 0.0));
// void process(double step) override;
// std::shared_ptr<PhysicsEngineSolverAdapter> getPhysicsEngineSolver();
// void distributeIDs();
// void setBlockVisitor(std::shared_ptr<BoundaryConditionsBlockVisitor> blockVisitor);
// bool isDemObjectInAABB(std::array<double, 6> AABB);
// int addSurfaceTriangleSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt3> &triangles);
// void getObjectsPropertiesVector(std::vector<double> &p);
// void addPeGeo(walberla::pe::RigidBody *peGeo);
// void removePeGeo(walberla::pe::RigidBody *peGeo);
// void addPeShadowGeo(walberla::pe::RigidBody *peGeo);
// void removePeShadowGeo(walberla::pe::RigidBody *peGeo);
// bool isSpheresIntersection(double centerX1, double centerX2, double centerX3, double d);
//
//private:
// std::shared_ptr<PhysicsEngineGeometryAdapter>
// createPhysicsEngineGeometryAdapter(std::shared_ptr<MovableObjectInteractor> interactor,
// std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial) const;
// void applyForcesOnGeometries();
// void setForcesToObject(SPtr<Grid3D> grid, std::shared_ptr<MovableObjectInteractor> interactor,
// std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry);
// void scaleForcesAndTorques(double scalingFactor);
// void calculateDemTimeStep(double step);
// void moveVfGeoObjects();
// walberla::pe::RigidBody *getPeGeoObject(walberla::id_t id);
// std::shared_ptr<PePhysicsEngineGeometryAdapter> getPeGeoAdapter(unsigned long long systemId);
//
//private:
// std::shared_ptr<Communicator> comm;
// std::vector<std::shared_ptr<MovableObjectInteractor>> interactors;
// std::shared_ptr<ForceCalculator> forceCalculator;
// std::shared_ptr<PePhysicsEngineSolverAdapter> physicsEngineSolver;
// std::vector<std::shared_ptr<PhysicsEngineGeometryAdapter>> physicsEngineGeometrieAdapters;
// double intermediateDemSteps;
// SPtr<BoundaryConditionsBlockVisitor> boundaryConditionsBlockVisitor;
// // walberla::pe::BodyStorage* bodyStorage; //!< Reference to the central body storage.
// // walberla::pe::BodyStorage* bodyStorageShadowCopies; //!< Reference to the body storage containing body shadow
// // copies.
//
// std::map<unsigned long long, std::shared_ptr<PePhysicsEngineGeometryAdapter>> geoIdMap;
//
//#ifdef TIMING
// UbTimer timer;
//#endif
//};
//
//#endif
/*
* This file is part of the LBDEMcoupling software.
*
* LBDEMcoupling 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, version 3.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Johannes Kepler University Linz
*
* Author: Philippe Seil (philippe.seil@jku.at)
*/
#include "LiggghtsCouplingWrapper.h"
#include "mpi.h"
#include <iostream>
#include <sstream>
LiggghtsCouplingWrapper::LiggghtsCouplingWrapper(char **argv, MPI_Comm communicator)
: lmp(0)
{
// todo: get LAMMPS to recognize command line options
int argc_lmp = 1;
char **argv_lmp = 0;
argv_lmp = new char*[1];
argv_lmp[0] = argv[0];
lmp = new LAMMPS_NS::LAMMPS(argc_lmp,argv_lmp,communicator);
// delete[] argv_lmp[0];
delete[] argv_lmp;
}
void LiggghtsCouplingWrapper::execFile(char* const fname)
{
lmp->input->file(fname);
}
void LiggghtsCouplingWrapper::execCommand(std::stringstream const &cmd)
{
lmp->input->one(cmd.str().c_str());
}
void LiggghtsCouplingWrapper::execCommand(char* const cmd)
{
lmp->input->one(cmd);
}
int LiggghtsCouplingWrapper::getNumParticles()
{
return lammps_get_natoms(lmp);
}
void LiggghtsCouplingWrapper::setVariable(char const *name, double value)
{
std::stringstream cmd;
cmd << "variable " << name << " equal " << value;
std::cout << cmd.str() << std::endl;
execCommand(cmd);
}
void LiggghtsCouplingWrapper::setVariable(char const *name, std::string &value)
{
std::stringstream cmd;
cmd << "variable " << name << " string " << value;
std::cout << cmd.str() << std::endl;
execCommand(cmd);
}
void LiggghtsCouplingWrapper::run(int nSteps)
{
std::stringstream cmd;
cmd << "run " << nSteps;
execCommand(cmd);
}
void LiggghtsCouplingWrapper::runUpto(int nSteps)
{
std::stringstream cmd;
cmd << "run " << nSteps << " upto";
execCommand(cmd);
}
/*
* This file is part of the LBDEMcoupling software.
*
* LBDEMcoupling 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, version 3.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Johannes Kepler University Linz
*
* Author: Philippe Seil (philippe.seil@jku.at)
*/
#ifndef LIGGGHTSCOUPLINGWRAPPER_H
#define LIGGGHTSCOUPLINGWRAPPER_H
// necessary LAMMPS/LIGGGHTS includes
#include "lammps.h"
#include "input.h"
#include "library.h"
#include "library_cfd_coupling.h"
class LiggghtsCouplingWrapper {
public:
LiggghtsCouplingWrapper(char **argv, MPI_Comm communicator);
void execFile(char* const fname);
void execCommand(std::stringstream const &cmd);
void execCommand(char* const cmd);
void run(int nSteps);
void runUpto(int nSteps);
int getNumParticles();
void setVariable(char const *name, double value);
void setVariable(char const *name, std::string &value);
//private:
LAMMPS_NS::LAMMPS *lmp;
};
#endif /* LIGGGHTSCOUPLINGWRAPPER_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment