ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/hydrodynamics/StuntDoubleShape.cpp
Revision: 2611
Committed: Mon Mar 13 22:42:40 2006 UTC (18 years, 3 months ago) by tim
File size: 7314 byte(s)
Log Message:
LangevinDynamics in progress

File Contents

# Content
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 "applications/hydrodynamics/StuntDoubleShape.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.second = 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.second = origin_ + r;
99 return boundary;
100 }
101
102
103 StuntDoubleShape::StuntDoubleShape(StuntDouble* sd) {
104 if (sd->isAtom()) {
105 Shape* currShape = createShape(static_cast<Atom*>(sd));
106
107 if (currShape != NULL)
108 shapes_.push_back(currShape);
109
110 } else if (sd->isRigidBody()) {
111 RigidBody* rb = static_cast<RigidBody*>(sd);
112 std::vector<Atom*>::iterator ai;
113 Atom* atom;
114 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
115 Shape* currShape = createShape(static_cast<Atom*>(sd));
116
117 if (currShape != NULL)
118 shapes_.push_back(currShape);
119 }
120 }
121
122 }
123
124 StuntDoubleShape::~StuntDoubleShape() {
125 MemoryUtils::deletePointers(shapes_);
126 }
127 bool StuntDoubleShape::isInterior(Vector3d pos) {
128 bool result = false;
129 std::vector<Shape*>::iterator iter;
130 for (iter = shapes_.begin(); iter != shapes_.end(); ++ iter) {
131 if ((*iter)->isInterior(pos)) {
132 result = true;
133 break;
134 }
135 }
136
137 return result;
138 }
139
140 Shape* StuntDoubleShape::createShape(Atom* atom) {
141 AtomType* atomType = atom->getAtomType();
142 Shape* currShape = NULL;
143 if (atomType->isGayBerne()) {
144 DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
145
146 GenericData* data = dAtomType->getPropertyByName("GayBerne");
147 if (data != NULL) {
148 GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
149
150 if (gayBerneData != NULL) {
151 GayBerneParam gayBerneParam = gayBerneData->getData();
152 currShape = new Ellipsoid(atom->getPos(), gayBerneParam.GB_sigma, gayBerneParam.GB_l2b_ratio, atom->getA());
153 } else {
154 sprintf( painCave.errMsg,
155 "Can not cast GenericData to GayBerneParam\n");
156 painCave.severity = OOPSE_ERROR;
157 painCave.isFatal = 1;
158 simError();
159 }
160 } else {
161 sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n");
162 painCave.severity = OOPSE_ERROR;
163 painCave.isFatal = 1;
164 simError();
165 }
166 } else if (atomType->isLennardJones()){
167 GenericData* data = atomType->getPropertyByName("LennardJones");
168 if (data != NULL) {
169 LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
170
171 if (ljData != NULL) {
172 LJParam ljParam = ljData->getData();
173 currShape = new Spheric(atom->getPos(), ljParam.sigma/2.0);
174 } else {
175 sprintf( painCave.errMsg,
176 "Can not cast GenericData to LJParam\n");
177 painCave.severity = OOPSE_ERROR;
178 painCave.isFatal = 1;
179 simError();
180 }
181 }
182
183 }
184
185 return currShape;
186 }
187
188 template<class Cont, class Predict>
189 void swap_if(Cont& b1, Cont& b2, Predict predict) {
190 unsigned int size = b1.size();
191 assert(size == b2.size());
192 for (unsigned int i = 0 ; i < size; ++i) {
193 if (predict(b1[i], b2[i]))
194 std::swap(b1[i], b2[i]);
195 }
196
197 }
198
199 std::pair<Vector3d, Vector3d> StuntDoubleShape::getBox() {
200 std::vector<Shape*>::iterator iter = shapes_.begin();
201 std::pair<Vector3d, Vector3d> boundary = (*iter)->getBox();
202 for (++iter; iter != shapes_.end(); ++iter) {
203 std::pair<Vector3d, Vector3d> currBoundary = (*iter)->getBox();
204 swap_if(boundary.first, currBoundary.first, std::less<double>());
205 swap_if(boundary.second, currBoundary.second, std::greater<double>());
206 }
207
208 return boundary;
209 }
210
211
212 }

Properties

Name Value
svn:executable *