ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/types/AtomType.cpp
Revision: 1813
Committed: Wed Dec 1 17:38:32 2004 UTC (19 years, 8 months ago) by tim
File size: 6146 byte(s)
Log Message:
refactory AtomType

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <iostream>
5
6 #include "types/AtomType.hpp"
7 #include "utils/simError.h"
8 #define __C
9 #include "UseTheForce/DarkSide/atype_interface.h"
10 #include "UseTheForce/DarkSide/lj_interface.h"
11 #include "UseTheForce/DarkSide/eam_interface.h"
12 #include "UseTheForce/DarkSide/charge_interface.h"
13 namespace oopse {
14 AtomType::AtomType(){
15
16 // initialize to an error:
17 atp.ident = -1;
18
19 // and mass_less:
20 mass_ = 0.0;
21
22 // atom type is a Tabula Rasa:
23 atp.is_Directional = 0;
24 atp.is_LennardJones = 0;
25 atp.is_Electrostatic = 0;
26 atp.is_Charge = 0;
27 atp.is_Dipole = 0;
28 atp.is_Multipole = 0;
29 atp.is_Sticky = 0;
30 atp.is_GayBerne = 0;
31 atp.is_EAM = 0;
32 atp.is_Shape = 0;
33 atp.is_FLARB = 0;
34 }
35
36 void AtomType::makeFortranAtomType() {
37
38 int status;
39
40 if (name_.empty()) {
41 sprintf( painCave.errMsg,
42 "Attempting to complete an AtomType without giving "
43 "it a name_!\n");
44 painCave.severity = OOPSE_ERROR;
45 painCave.isFatal = 1;
46 simError();
47 }
48
49 if (atp.ident == -1) {
50 sprintf( painCave.errMsg,
51 "Attempting to complete AtomType %s without setting the"
52 " ident!/n", name_.c_str());
53 painCave.severity = OOPSE_ERROR;
54 painCave.isFatal = 1;
55 simError();
56 }
57
58 status = 0;
59
60 makeAtype(&atp, &status);
61
62 if (status != 0) {
63 sprintf( painCave.errMsg,
64 "Fortran rejected AtomType %s!\n", name_.c_str());
65 painCave.severity = OOPSE_ERROR;
66 painCave.isFatal = 1;
67 simError();
68 }
69 }
70
71
72 void AtomType::complete() {
73 int isError;
74 GenericData* data;
75
76 //notify a new LJtype atom type is created
77 if (isLennardJones()) {
78 data = getPropertyByName("LennardJones");
79 if (data != NULL) {
80 LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
81
82 if (ljData != NULL) {
83 LJParam ljParam = ljData->getData();
84
85 newLJtype(&atp.ident, &ljParam.sigma, &ljParam.epsilon, &isError);
86
87 if (isError != 0) {
88 sprintf( painCave.errMsg,
89 "Fortran rejected newLJtype\n");
90 painCave.severity = OOPSE_ERROR;
91 painCave.isFatal = 1;
92 simError();
93 }
94
95 } else {
96 sprintf( painCave.errMsg,
97 "Can not cast GenericData to LJParam\n");
98 painCave.severity = OOPSE_ERROR;
99 painCave.isFatal = 1;
100 simError();
101 }
102 } else {
103 sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
104 painCave.severity = OOPSE_ERROR;
105 painCave.isFatal = 1;
106 simError();
107 }
108 }
109
110 if (isCharge()) {
111 data = getPropertyByName("Charge");
112 if (data != NULL) {
113 DoubleGenericData* doubleData= dynamic_cast<DoubleGenericData*>(data);
114
115 if (doubleData != NULL) {
116 double charge = doubleData->getData();
117 newChargeType(&atp.ident, &charge, &isError);
118
119 if (isError != 0) {
120 sprintf( painCave.errMsg,
121 "Fortran rejected newChargeType\n");
122 painCave.severity = OOPSE_ERROR;
123 painCave.isFatal = 1;
124 simError();
125 }
126 } else {
127 sprintf( painCave.errMsg,
128 "Can not cast GenericData to DoubleGenericData\n");
129 painCave.severity = OOPSE_ERROR;
130 painCave.isFatal = 1;
131 simError();
132 }
133 } else {
134 sprintf( painCave.errMsg, "Can not find Charge Parameters\n");
135 painCave.severity = OOPSE_ERROR;
136 painCave.isFatal = 1;
137 simError();
138 }
139 }
140
141 if (isEAM()) {
142 data = getPropertyByName("EAM");
143 if (data != NULL) {
144 EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
145
146 if (eamData != NULL) {
147
148 EAMParam eamParam = eamData->getData();
149
150
151 newEAMtype(&eamParam.latticeConstant, &eamParam.nrho, &eamParam.drho, &eamParam.nr, &eamParam.dr, &eamParam.rcut,
152 &eamParam.rvals[0], &eamParam.rhovals[0], &eamParam.Frhovals[0], &atp.ident, &isError );
153
154 if (isError != 0) {
155 sprintf( painCave.errMsg,
156 "Fortran rejected newEAMtype\n");
157 painCave.severity = OOPSE_ERROR;
158 painCave.isFatal = 1;
159 simError();
160 }
161 } else {
162 sprintf( painCave.errMsg,
163 "Can not cast GenericData to EAMParam\n");
164 painCave.severity = OOPSE_ERROR;
165 painCave.isFatal = 1;
166 simError();
167 }
168 } else {
169 sprintf( painCave.errMsg, "Can not find EAM Parameters\n");
170 painCave.severity = OOPSE_ERROR;
171 painCave.isFatal = 1;
172 simError();
173 }
174 }
175
176
177 }
178
179 void AtomType::addProperty(GenericData* genData) {
180 properties_.addProperty(genData);
181 }
182
183 void AtomType::removeProperty(const std::string& propName) {
184 properties_.removeProperty(propName);
185 }
186
187 void AtomType::clearProperties() {
188 properties_.clearProperties();
189 }
190
191 std::vector<std::string> AtomType::getPropertyNames() {
192 return properties_.getPropertyNames();
193 }
194
195 std::vector<GenericData*> AtomType::getProperties() {
196 return properties_.getProperties();
197 }
198
199 GenericData* AtomType::getPropertyByName(const std::string& propName) {
200 return properties_.getPropertyByName(propName);
201 }
202 }