ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/hydrodynamics/MoleculeShape.cpp
Revision: 891
Committed: Wed Feb 22 20:35:16 2006 UTC (19 years, 2 months ago) by tim
File size: 6866 byte(s)
Log Message:
Adding Hydrodynamics Module

File Contents

# User Rev Content
1 tim 891 /*
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 "applications/hydrodynamics/MoleculeShape.hpp"
43     #include "utils/MemoryUtils.hpp"
44    
45     namespace oopse {
46    
47     Spheric::Spheric(Vector3d origin, double radius) : origin_(origin), radius_(radius){
48    
49     }
50    
51     bool Spheric::isInterior(Vector3d pos) {
52     Vector3d r = pos - origin_;
53    
54     bool result;
55     if (r.length() < radius_)
56     result = true;
57     else
58     result = false;
59    
60     return result;
61     }
62    
63     std::pair<Vector3d, Vector3d> Spheric::getBox() {
64     std::pair<Vector3d, Vector3d> boundary;
65     Vector3d r(radius_, radius_, radius_);
66     boundary.first = origin_ - r;
67     boundary.first = origin_ + r;
68     return boundary;
69     }
70     Ellipsoid::Ellipsoid(Vector3d origin, double radius, double ratio, Mat3x3d rotMat)
71     : origin_(origin), a_(radius), b_(radius*ratio), rotMat_(rotMat) {
72    
73     }
74     bool Ellipsoid::isInterior(Vector3d pos) {
75     Vector3d r = pos - origin_;
76     Vector3d rbody = rotMat_ * r;
77     double xovera = rbody[0]/a_;
78     double yovera = rbody[1]/a_;
79     double zoverb = rbody[2]/b_;
80    
81     bool result;
82     if (xovera*xovera + yovera*yovera + zoverb*zoverb < 1)
83     result = true;
84     else
85     result = false;
86    
87     return result;
88    
89     }
90    
91     std::pair<Vector3d, Vector3d> Ellipsoid::getBox() {
92    
93     std::pair<Vector3d, Vector3d> boundary;
94     //make a cubic box
95     double rad = a_ > b_ ? a_ : b_;
96     Vector3d r(rad, rad, rad);
97     boundary.first = origin_ - r;
98     boundary.first = origin_ + r;
99     return boundary;
100     }
101    
102    
103     MoleculeShape::MoleculeShape(Molecule* mol) {
104     std::vector<Atom*>::iterator ai;
105     Atom* atom;
106     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
107     AtomType* atomType = atom->getAtomType();
108     Shape* currShape = NULL;
109     if (atomType->isGayBerne()) {
110     DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
111    
112     GenericData* data = dAtomType->getPropertyByName("GayBerne");
113     if (data != NULL) {
114     GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
115    
116     if (gayBerneData != NULL) {
117     GayBerneParam gayBerneParam = gayBerneData->getData();
118     currShape = new Ellipsoid(atom->getPos(), gayBerneParam.GB_sigma, gayBerneParam.GB_l2b_ratio, atom->getA());
119     } else {
120     sprintf( painCave.errMsg,
121     "Can not cast GenericData to GayBerneParam\n");
122     painCave.severity = OOPSE_ERROR;
123     painCave.isFatal = 1;
124     simError();
125     }
126     } else {
127     sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n");
128     painCave.severity = OOPSE_ERROR;
129     painCave.isFatal = 1;
130     simError();
131     }
132     } else if (atomType->isLennardJones()){
133     GenericData* data = atomType->getPropertyByName("LennardJones");
134     if (data != NULL) {
135     LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
136    
137     if (ljData != NULL) {
138     LJParam ljParam = ljData->getData();
139     currShape = new Spheric(atom->getPos(), ljParam.sigma/2.0);
140     } else {
141     sprintf( painCave.errMsg,
142     "Can not cast GenericData to LJParam\n");
143     painCave.severity = OOPSE_ERROR;
144     painCave.isFatal = 1;
145     simError();
146     }
147     }
148    
149     }
150    
151     if (currShape != NULL)
152     shapes_.push_back(currShape);
153    
154     }
155    
156     }
157    
158     MoleculeShape::~MoleculeShape() {
159     MemoryUtils::deletePointers(shapes_);
160     }
161     bool MoleculeShape::isInterior(Vector3d pos) {
162     bool result = false;
163     std::vector<Shape*>::iterator iter;
164     for (iter = shapes_.begin(); iter != shapes_.end(); ++ iter) {
165     if ((*iter)->isInterior(pos)) {
166     result = true;
167     break;
168     }
169     }
170    
171     return result;
172     }
173    
174     template<class Cont, class Predict>
175     void swap_if(Cont& b1, Cont& b2, Predict predict) {
176     unsigned int size = b1.size();
177     assert(size == b2.size());
178     for (unsigned int i = 0 ; i < size; ++i) {
179     if (predict(b1[i], b2[i]))
180     std::swap(b1[i], b2[i]);
181     }
182    
183     }
184    
185     std::pair<Vector3d, Vector3d> MoleculeShape::getBox() {
186     std::vector<Shape*>::iterator iter = shapes_.begin();
187     std::pair<Vector3d, Vector3d> boundary = (*iter)->getBox();
188     for (++iter; iter != shapes_.end(); ++iter) {
189     std::pair<Vector3d, Vector3d> currBoundary = (*iter)->getBox();
190     swap_if(boundary.first, currBoundary.first, std::less<double>());
191     swap_if(boundary.second, currBoundary.second, std::greater<double>());
192     }
193    
194     return boundary;
195     }
196    
197    
198     }

Properties

Name Value
svn:executable *