Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First design of MD capability in Magpie #369

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/content/source/auxkernels/MDNParticleAux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# MDNParticleAux

!syntax description /AuxKernels/MDNParticleAux

Injects the number of MD particles per element computed by
MD runner object into an auxiliary variable.

!syntax parameters /AuxKernels/MDNParticleAux

!syntax inputs /AuxKernels/MDNParticleAux

!syntax children /AuxKernels/MDNParticleAux

!bibtex bibliography
21 changes: 21 additions & 0 deletions doc/content/source/userobjects/LAMMPSFileRunner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# LAMMPSFileRunner

`LAMMPSFileRunner` reads in LAMMPS dumps file and maps them on an FEM mesh.
The `time_sequence` parameter determines if a sequence of LAMMPS files is read
or a single file is loaded and used throughout. If a sequence of files is used,
the `lammps_file` parameter should contain the file base, e.g. `path/to/file/filebase`
if the files are called `path/to/file/filebase.<time>.xyz`.

Time conversion from FEM time to LAMMPS time is facilitated by the `time_conversion`
parameter that accepts a MOOSE function object. Denoting FEM time by `t` and LAMMPS time
by `T`, `time_conversion` is a function `T = F(t)`.

!syntax description /UserObjects/LAMMPSFileRunner

!syntax parameters /UserObjects/LAMMPSFileRunner

!syntax inputs /UserObjects/LAMMPSFileRunner

!syntax children /UserObjects/LAMMPSFileRunner

!bibtex bibliography
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
62 changes: 62 additions & 0 deletions include/userobjects/LAMMPSFileRunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**********************************************************************/
/* 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;
class Function;

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 x, y, z coordinate in LAMMPS files
std::vector<unsigned int> _pos_columns;

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

#endif // LAMMPSFILERUNNER_H
96 changes: 96 additions & 0 deletions include/userobjects/MDRunBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**********************************************************************/
/* 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
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<unique_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(unique_id_type elem_id) const;

/// List of quantities to get from MD simulation
MultiMooseEnum getMDQuantities() 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<unique_id_type, std::vector<unsigned int>> _elem_particles;

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

#endif // MDRUNBASE_H
34 changes: 34 additions & 0 deletions src/auxkernels/MDNParticleAux.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**********************************************************************/
/* 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");
params.addClassDescription("Injects the number of MD particles from MDRunBase object user_object "
"into auxiliary variable.");
return params;
}

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

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