Bsoft  2.1.0
Bernard's software package
model_poly_delta.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "model_poly.h"
11 #include "model_links.h"
12 #include "model_util.h"
13 #include "utilities.h"
14 
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17 
24 Bmodel* model_delta_create_tube_old(int radius, int height)
25 {
26  Bstring id("Tube");
27  Bmodel* model = model_init(id);
28 
29  Bstring hextype("HEX");
30  int i, nv;
31  double a, sa, ea;
32  int c = (int) (TWOPI*radius + 0.5);
33  double rad = c*1.0L/TWOPI;
34  double da = 1.0L/rad;
35  Bcomponent* comp = NULL;
36  Vector3<double> loc;
37 
38  if ( verbose & VERB_LABEL )
39  cout << "Generating a tubular deltagraph" << endl;
40 
41  if ( verbose & VERB_PROCESS ) {
42  cout << "Radius: " << rad << endl;
43  cout << "Height: " << height << endl;
44  }
45 
46  for ( nv=0, i=0; i<=height; i++ ) {
47  loc[2] = (i-height/2.0)*sqrt(3.0)/2.0;
48  sa = 0;
49  if ( i%2 ) sa = da/2;
50  ea = TWOPI - da/2 + sa;
51  for ( a=sa; a<ea; a+=da ) {
52  loc[0] = radius*cos(a);
53  loc[1] = radius*sin(a);
54  id = Bstring(++nv, "%d");
55  comp = component_add(&comp, id);
56  if ( !model->comp ) model->comp = comp;
57  comp->type = model_add_type_by_id(model, hextype);
58  comp->loc = loc;
59  comp->radius = 0.1;
60  }
61  }
62 
64 
65  return model;
66 }
67 
78 Bmodel* model_delta_create_tube(int h, int k, int height)
79 {
80  Bstring id("Tube");
81  Bmodel* model = model_init(id);
82 
83  Bstring hextype("HEX");
84  int nv(0), close;
85  double c = sqrt(h*h + h*k + k*k);
86  double rad = c/TWOPI;
87  double bottom = -height/2.0, top = height/2.0;
88  Bcomponent* comp = NULL;
89  Bcomponent* comp2 = NULL;
90  Vector3<double> lat, start, loc;
91 
92  if ( verbose & VERB_LABEL )
93  cout << "Generating a tubular deltagraph" << endl;
94 
95  if ( verbose & ( VERB_LABEL | VERB_PROCESS ) ) {
96  cout << "Lattice parameters: " << h << " " << k << endl;
97  cout << "Radius: " << rad << endl;
98  cout << "Height: " << height << endl;
99  }
100 
101  double a = atan2(k*sqrt(3.0)/2, h+k/2.0);
102  Vector3<double> u(cos(a), -sin(a), 0), v(cos(M_PI/3-a), sin(M_PI/3-a), 0);
103  Vector3<double> w = v - u;
104 
105  while ( w[0] > 0 ) w -= u;
106 
107  start[1] = bottom;
108  while ( lat[1] < top ) {
109  for ( lat = start; lat[0] < c; lat += u ) {
110  if ( lat[0] >= 0 && lat[0] < c && lat[1] >= bottom && lat[1] <= top ) {
111  a = lat[0]/rad;
112  loc[0] = rad*cos(a);
113  loc[1] = rad*sin(a);
114  loc[2] = lat[1];
115  for ( close=0, comp2 = model->comp; comp2 && !close; comp2 = comp2->next )
116  if ( comp2->loc.distance(loc) < 0.5 ) close = 1;
117  if ( !close ) {
118  id = Bstring(++nv, "%d");
119  comp = component_add(&comp, id);
120  if ( !model->comp ) model->comp = comp;
121  comp->type = model_add_type_by_id(model, hextype);
122  comp->loc = loc;
123  comp->radius = 0.1;
124  }
125  }
126  }
127  start += w;
128  }
129 
130  if ( verbose )
131  cout << "Number of components generated: " << nv << endl << endl;
132 
134 
135  return model;
136 }
137 
152 Bmodel* model_delta_create_cylinder(int type, int radius, int height)
153 {
154  int order = 6;
155  if ( type & 2 ) order = 5;
156 
157  Bstring id("Cylinder");
158  Bmodel* model = model_init(id);
159  model->symmetry = "D6";
160  if ( type & 2 ) model->symmetry = "D5";
161 
162  Bstring pentype("PEN");
163  Bstring hextype("HEX");
164  int i, nv(1);
165  double a, sa(0), ea, f;
166  double da = TWOPI/(1.0L*order);
167  double hra = da/(2*radius);
168  Bcomponent* comp;
169  Vector3<double> start, vec;
170 
171  if ( verbose & VERB_LABEL )
172  cout << "Generating a cylindrical deltagraph" << endl;
173 
174  if ( type & 4 ) {
175  id = "1";
176  comp = component_add(&model->comp, id);
177  if ( order == 5 ) comp->type = model_add_type_by_id(model, pentype);
178  else comp->type = model_add_type_by_id(model, hextype);
179  comp->loc[2] = -height*sqrt(3.0)/4.0 - 0.5*radius;
180  ea = TWOPI - da/2.0;
181  for ( i=1; i<=radius; i++ ) {
182  start[2] = -height*sqrt(3.0)/4.0 - 0.5*(radius - i);
183  for ( a=0; a<ea; a+=da ) {
184  start[0] = i*cos(a);
185  start[1] = i*sin(a);
186  vec[0] = i*cos(a+da) - start[0];
187  vec[1] = i*sin(a+da) - start[1];
188  for ( f=0; f<0.95; f+=1.0L/i ) {
189  id = Bstring(++nv, "%d");
190  comp = component_add(&comp, id);
191  if ( i == radius && f == 0 ) comp->type = model_add_type_by_id(model, pentype);
192  else comp->type = model_add_type_by_id(model, hextype);
193  comp->loc = start + vec*f;
194  }
195  }
196  }
197  }
198 
199  for ( i=1; i<height; i++ ) {
200  start[2] = (i-height/2.0)*sqrt(3.0)/2.0;
201  sa = 0;
202  if ( i%2 ) sa = hra;
203  ea = TWOPI - hra + sa;
204  for ( a=sa; a<ea; a+=da ) {
205  start[0] = radius*cos(a);
206  start[1] = radius*sin(a);
207  if ( height%2 == 0 || start[2] < 0 ) {
208  vec[0] = radius*cos(a+da-2*sa) - start[0];
209  vec[1] = radius*sin(a+da-2*sa) - start[1];
210  if ( sa && radius > 1 ) vec *= radius/(radius - 1.0);
211  } else {
212  if ( sa == 0 ) {
213  start[0] = radius*cos(a+2*hra);
214  start[1] = radius*sin(a+2*hra);
215  vec[0] = radius*cos(a+da) - start[0];
216  vec[1] = radius*sin(a+da) - start[1];
217  if ( radius > 1 ) vec *= radius/(radius - 1.0);
218  } else {
219  vec[0] = radius*cos(a+da) - start[0];
220  vec[1] = radius*sin(a+da) - start[1];
221  }
222  }
223  for ( f=0; f<0.95; f+=1.0L/radius ) {
224  id = Bstring(++nv, "%d");
225  comp = component_add(&model->comp, id);
226  comp->type = model_add_type_by_id(model, hextype);
227  comp->loc = start + vec*f;
228  }
229  }
230  }
231 
232  if ( type & 8 ) {
233  if ( sa > 0 ) sa = 0;
234  else sa = hra;
235  for ( i=radius; i>0; i-- ) {
236  start[2] = height*sqrt(3.0)/4.0 + 0.5*(radius - i);
237  ea = TWOPI - hra + sa;
238  for ( a=sa; a<ea; a+=da ) {
239  start[0] = i*cos(a);
240  start[1] = i*sin(a);
241  vec[0] = i*cos(a+da) - start[0];
242  vec[1] = i*sin(a+da) - start[1];
243  for ( f=0; f<0.95; f+=1.0L/i ) {
244  id = Bstring(++nv, "%d");
245  comp = component_add(&comp, id);
246  if ( i == radius && f == 0 ) comp->type = model_add_type_by_id(model, pentype);
247  else comp->type = model_add_type_by_id(model, hextype);
248  comp->loc = start + vec*f;
249  if ( verbose & VERB_FULL ) cout << comp->id << ":\t" << comp->loc << endl;
250  }
251  }
252  }
253 
254  id = Bstring(++nv, "%d");
255  comp = component_add(&comp, id);
256  if ( order == 5 ) comp->type = model_add_type_by_id(model, pentype);
257  else comp->type = model_add_type_by_id(model, hextype);
258  comp->loc[2] = height*sqrt(3.0)/4.0 + 0.5*radius;
259  }
260 
262 
263  return model;
264 }
265 
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
Bcomponent
Definition: rwmodel.h:51
rwmodel.h
Header file for reading and writing atomic model files.
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bstring
Definition: Bstring.h:29
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:270
Vector3< double >
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
model_init
Bmodel * model_init(Bstring &id)
Initializes a model structure.
Definition: rwmodel.cpp:147
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
model_delta_create_tube
Bmodel * model_delta_create_tube(int h, int k, int height)
Generates a new tubular deltagraph.
Definition: model_poly_delta.cpp:78
Bmodel
Definition: rwmodel.h:119
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
model
Bmodel * model
Definition: bshow.cpp:34
verbose
int verbose
model_poly.h
Functions to manipulate polyhedral coordinate files.
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
model_util.h
Library routines used for model processing.
model_add_type_by_id
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Definition: rwmodel.cpp:414
Bcomponent::radius
float radius
Definition: rwmodel.h:62
model_delta_create_cylinder
Bmodel * model_delta_create_cylinder(int type, int radius, int height)
Generates a new deltagraph based on the type.
Definition: model_poly_delta.cpp:152
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
TWOPI
#define TWOPI
Definition: utilities.h:72
model_delta_create_tube_old
Bmodel * model_delta_create_tube_old(int radius, int height)
Generates a new tubular deltagraph.
Definition: model_poly_delta.cpp:24