| 1 |
/* |
| 2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
* |
| 4 |
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
* non-exclusive, royalty free, license to use, modify and |
| 6 |
* redistribute this software in source and binary code form, provided |
| 7 |
* that the following conditions are met: |
| 8 |
* |
| 9 |
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
* publication of scientific results based in part on use of the |
| 11 |
* program. An acceptable form of acknowledgement is citation of |
| 12 |
* the article in which the program was described (Matthew |
| 13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
* |
| 18 |
* 2. Redistributions of source code must retain the above copyright |
| 19 |
* notice, this list of conditions and the following disclaimer. |
| 20 |
* |
| 21 |
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
* notice, this list of conditions and the following disclaimer in the |
| 23 |
* documentation and/or other materials provided with the |
| 24 |
* distribution. |
| 25 |
* |
| 26 |
* This software is provided "AS IS," without a warranty of any |
| 27 |
* kind. All express or implied conditions, representations and |
| 28 |
* warranties, including any implied warranty of merchantability, |
| 29 |
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
* be liable for any damages suffered by licensee as a result of |
| 32 |
* using, modifying or distributing the software or its |
| 33 |
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
* damages, however caused and regardless of the theory of liability, |
| 37 |
* arising out of the use of or inability to use software, even if the |
| 38 |
* University of Notre Dame has been advised of the possibility of |
| 39 |
* such damages. |
| 40 |
*/ |
| 41 |
|
| 42 |
#include <iostream> |
| 43 |
#include <fstream> |
| 44 |
#include <string> |
| 45 |
|
| 46 |
#include "applications/hydrodynamics/HydroCmd.h" |
| 47 |
#include "applications/hydrodynamics/HydrodynamicsModel.hpp" |
| 48 |
#include "applications/hydrodynamics/HydrodynamicsModelCreator.hpp" |
| 49 |
#include "applications/hydrodynamics/HydrodynamicsModelFactory.hpp" |
| 50 |
#include "applications/hydrodynamics/BeadModel.hpp" |
| 51 |
#include "applications/hydrodynamics/RoughShell.hpp" |
| 52 |
#include "brains/Register.hpp" |
| 53 |
#include "brains/SimCreator.hpp" |
| 54 |
#include "brains/SimInfo.hpp" |
| 55 |
|
| 56 |
using namespace oopse; |
| 57 |
|
| 58 |
/** Register different hydrodynamics models */ |
| 59 |
void registerHydrodynamicsModels(); |
| 60 |
|
| 61 |
bool calcHydrodynamicsProp(const std::string& modelType, StuntDouble* sd, const DynamicProperty& param, std::ostream& os, const std::string& prefix); |
| 62 |
|
| 63 |
int main(int argc, char* argv[]){ |
| 64 |
//register force fields |
| 65 |
registerForceFields(); |
| 66 |
registerHydrodynamicsModels(); |
| 67 |
|
| 68 |
gengetopt_args_info args_info; |
| 69 |
std::string dumpFileName; |
| 70 |
std::string mdFileName; |
| 71 |
std::string prefix; |
| 72 |
|
| 73 |
//parse the command line option |
| 74 |
if (cmdline_parser (argc, argv, &args_info) != 0) { |
| 75 |
exit(1) ; |
| 76 |
} |
| 77 |
|
| 78 |
//get the dumpfile name and meta-data file name |
| 79 |
if (args_info.input_given){ |
| 80 |
dumpFileName = args_info.input_arg; |
| 81 |
} else { |
| 82 |
std::cerr << "Does not have input file name" << std::endl; |
| 83 |
exit(1); |
| 84 |
} |
| 85 |
|
| 86 |
mdFileName = dumpFileName; |
| 87 |
mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md"; |
| 88 |
|
| 89 |
if (args_info.output_given){ |
| 90 |
prefix = args_info.output_arg; |
| 91 |
} else { |
| 92 |
prefix = "hydro"; |
| 93 |
} |
| 94 |
std::string outputFilename = prefix + ".diff"; |
| 95 |
|
| 96 |
DynamicProperty param; |
| 97 |
param.insert(DynamicProperty::value_type("Viscosity", args_info.viscosity_arg)); |
| 98 |
param.insert(DynamicProperty::value_type("Temperature", args_info.temperature_arg)); |
| 99 |
|
| 100 |
if (args_info.sigma_given) { |
| 101 |
param.insert(DynamicProperty::value_type("Sigma", args_info.sigma_arg)); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
//parse md file and set up the system |
| 106 |
SimCreator creator; |
| 107 |
SimInfo* info = creator.createSim(mdFileName, true); |
| 108 |
|
| 109 |
SimInfo::MoleculeIterator mi; |
| 110 |
Molecule* mol; |
| 111 |
Molecule::IntegrableObjectIterator ii; |
| 112 |
StuntDouble* integrableObject; |
| 113 |
Mat3x3d identMat; |
| 114 |
identMat(0,0) = 1.0; |
| 115 |
identMat(1,1) = 1.0; |
| 116 |
identMat(2,2) = 1.0; |
| 117 |
|
| 118 |
|
| 119 |
std::map<std::string, StuntDouble*> uniqueStuntDoubles; |
| 120 |
|
| 121 |
for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { |
| 122 |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
| 123 |
integrableObject = mol->nextIntegrableObject(ii)) { |
| 124 |
if (uniqueStuntDoubles.find(integrableObject->getType()) == uniqueStuntDoubles.end()) { |
| 125 |
uniqueStuntDoubles.insert(std::map<std::string, StuntDouble*>::value_type(integrableObject->getType(), integrableObject)); |
| 126 |
integrableObject->setPos(V3Zero); |
| 127 |
integrableObject->setA(identMat); |
| 128 |
if (integrableObject->isRigidBody()) { |
| 129 |
RigidBody* rb = static_cast<RigidBody*>(integrableObject); |
| 130 |
rb->updateAtoms(); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
std::map<std::string, StuntDouble*>::iterator iter; |
| 137 |
std::ofstream outputDiff(outputFilename.c_str()); |
| 138 |
for (iter = uniqueStuntDoubles.begin(); iter != uniqueStuntDoubles.end(); ++iter) { |
| 139 |
calcHydrodynamicsProp(args_info.model_arg, iter->second, param, outputDiff, prefix); |
| 140 |
} |
| 141 |
|
| 142 |
delete info; |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
void registerHydrodynamicsModels() { |
| 147 |
HydrodynamicsModelFactory::getInstance()->registerHydrodynamicsModel(new HydrodynamicsModelBuilder<RoughShell>("RoughShell")); |
| 148 |
HydrodynamicsModelFactory::getInstance()->registerHydrodynamicsModel(new HydrodynamicsModelBuilder<BeadModel>("BeadModel")); |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
bool calcHydrodynamicsProp(const std::string& modelType, StuntDouble* sd, const DynamicProperty& param, std::ostream& os, const std::string& prefix) { |
| 153 |
HydrodynamicsModel* hydroModel = HydrodynamicsModelFactory::getInstance()->createHydrodynamicsModel(modelType, sd, param); |
| 154 |
bool ret = false; |
| 155 |
if (hydroModel == NULL) { |
| 156 |
std::cout << "Integrator Factory can not create " << modelType <<std::endl; |
| 157 |
} |
| 158 |
|
| 159 |
if (hydroModel->calcHydrodyanmicsProps()) { |
| 160 |
ret = true; |
| 161 |
hydroModel->writeDiffCenterAndDiffTensor(os); |
| 162 |
|
| 163 |
std::ofstream ofs; |
| 164 |
std::stringstream outputBeads; |
| 165 |
outputBeads << prefix << "_" << sd->getType() << ".xyz"; |
| 166 |
ofs.open(outputBeads.str().c_str()); |
| 167 |
hydroModel->writeBeads(ofs); |
| 168 |
ofs.close(); |
| 169 |
} |
| 170 |
|
| 171 |
delete hydroModel; |
| 172 |
|
| 173 |
return ret; |
| 174 |
} |