Skip to content

Commit

Permalink
First design of MD capability in Magpie (idaholab#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schunert committed Jan 30, 2019
1 parent 80c406d commit 2822d60
Show file tree
Hide file tree
Showing 16 changed files with 871 additions and 0 deletions.
33 changes: 33 additions & 0 deletions include/auxkernels/MDNParticleAux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#ifndef MDNPARTICLEAUX_H
#define MDNPARTICLEAUX_H

#include "AuxKernel.h"

// forward declarations
class MDRunBase;
class MDNParticleAux;

template <>
InputParameters validParams<MDNParticleAux>();

class MDNParticleAux : public AuxKernel
{
public:
MDNParticleAux(const InputParameters & params);
virtual ~MDNParticleAux() {}

virtual Real computeValue();

protected:
const MDRunBase & _md_uo;
};

#endif // MDNPARTICLEAUX_H
67 changes: 67 additions & 0 deletions include/userobjects/LAMMPSFileRunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#ifndef LAMMPSFILERUNNER_H
#define LAMMPSFILERUNNER_H

#include "MDRunBase.h"

class LAMMPSFileRunner;

template <>
InputParameters validParams<LAMMPSFileRunner>();

/**
* Reads lammps dump files to emulate MD simulation
*/
class LAMMPSFileRunner : public MDRunBase
{
public:
LAMMPSFileRunner(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override {}
virtual void finalize() override {}
virtual void initialSetup() override;

virtual void updateParticleList() override;

protected:
/// reads a LAMMPS file
void readLAMMPSFile(FileName filename);

/// reads two LAMMPS files and interpolates times
void readLAMMPSFileHistory(std::pair<FileName, FileName> filenames,
std::pair<Real, Real> timestamps,
Real current_time);

/// helper function that finds two files, one right before and one right after md_time
void findBracketingLAMMPSFiles(Real md_time,
std::pair<std::string, std::string> & filenames,
std::pair<Real, Real> & timestamps);

/// whether a sequence of input files or a single input file is read
bool _time_sequence;

/// name of LAMMPS file or file base if _time_sequence == true
FileName _lammps_file;

/// column of , y, z coordinate in LAMMPS files
std::vector<unsigned int> _pos_columns;

/// get velocity from file or compute it from positions
bool _velocity_from_file;

/// column of , y, z coordinate in LAMMPS files
std::vector<unsigned int> _vel_columns;

/// Conversion from FEM time to MD time_stamp
Function * _time_conversion;
};

#endif // LAMMPSFILERUNNER_H
93 changes: 93 additions & 0 deletions include/userobjects/MDRunBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#ifndef MDRUNBASE_H
#define MDRUNBASE_H

#include "GeneralUserObject.h"
#include "KDTree.h"
#include "libmesh/bounding_box.h"

class MDRunBase;
class MooseMesh;

template <>
InputParameters validParams<MDRunBase>();

/**
* Base class for molecular dynamics runs in Magpie
*/
class MDRunBase : public GeneralUserObject
{
public:
MDRunBase(const InputParameters & parameters);

void initialSetup() override;
void timestepSetup() override;

class MDParticles
{
public:
/// particle's position and history
std::vector<Point> pos;

/// particle's velocity
std::vector<Point> vel;

/// the id of particle in the MD calculation
std::vector<unsigned int> id;

/// the mesh element the particles are in
std::vector<dof_id_type> elem_id;
};

/// access to the MDParticles
const MDParticles & particles() const { return _md_particles; }

/// access to the element to particle map
const std::vector<unsigned int> elemParticles(dof_id_type elem_id) const;

protected:
/// call back function to update the particle list
virtual void updateParticleList() = 0;

/// updates the KDTree object
void updateKDTree();

/// map MDParticles to elements
void mapMDParticles();

/// The Mesh we're using
MooseMesh & _mesh;

/// dimension of the mesh
const unsigned int _dim;

/// dimension of the mesh
const unsigned int _nproc;

/// stores bounding boxes of all other processors
std::vector<BoundingBox> _bbox;

/// total number of particles
unsigned int _n_particles;

/// number of local particles
unsigned int _n_local_particles;

/// stores the location of
MDParticles _md_particles;

/// a map from elem pointer to particles in this element
std::map<dof_id_type, std::vector<unsigned int>> _elem_particles;

/// A KDTree object to handle md_particles
std::unique_ptr<KDTree> _kd_tree;
};

#endif // MDRUNBASE_H
33 changes: 33 additions & 0 deletions src/auxkernels/MDNParticleAux.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#include "MDNParticleAux.h"
#include "MDRunBase.h"

registerMooseObject("MagpieApp", MDNParticleAux);

template <>
InputParameters
validParams<MDNParticleAux>()
{
InputParameters params = validParams<AuxKernel>();
params.addRequiredParam<UserObjectName>("user_object", "Name of MD runner UserObject");
return params;
}

MDNParticleAux::MDNParticleAux(const InputParameters & parameters)
: AuxKernel(parameters),
_md_uo(getUserObject<MDRunBase>("user_object"))
{
}

Real
MDNParticleAux::computeValue()
{
return _md_uo.elemParticles(_current_elem->id()).size();
}
Loading

0 comments on commit 2822d60

Please sign in to comment.