source: sasview/src/sas/sascalc/simulation/pointsmodelpy/tests/testlores.cc @ cf2e6b4

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since cf2e6b4 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 4.0 KB
Line 
1#include <cstdlib>
2#include <iostream>
3#include <fstream>
4#include <vector>
5#include "lores_model.h"
6#include "sphere.h"
7#include "cylinder.h"
8#include "ellipsoid.h"
9#include "Point3D.h"
10
11using namespace std;
12
13void test_calculateIQ(LORESModel &lm);
14
15void WritePointsCoor(vector<Point3D> &vp){
16  ofstream outfile("testcc.coor");
17  for(size_t i=0; i<vp.size(); ++i){
18    outfile<<vp[i].getX()<<" "<<vp[i].getY()<<" "<<vp[i].getZ()<<" "<<1.0<<endl;
19  }
20}
21
22void test_lores(){
23
24  LORESModel lm(0.5);
25  cout << "density is:" << lm.GetDensity() << endl;
26   
27  Sphere s1(10);
28  s1.SetOrientation(10,10,20);
29  s1.SetCenter(10,10,10);
30  lm.Add(s1,1.0);
31   
32  Cylinder c1(5,20);
33  c1.SetCenter(0,0,0);
34  c1.SetOrientation(10,20,30);
35  lm.Add(c1,1.0);
36 
37  /*
38  Cylinder c2(40,100);
39  c2.SetCenter(-30,-40,-35);
40  lm.Add(c2,1.0);
41  */
42  /*
43  Ellipsoid e1(20,15,10);
44  e1.SetCenter(0,0,0);
45  e1.SetOrientation(10,10,20);
46  lm.Add(e1,1.0);
47  */
48  /*test multiple spheres
49  int range = 20;
50  int r = 5;
51  for (int k = 0; k < 1000; ++k) {
52    Sphere s(r + rand() % r);
53    s.SetCenter(rand() % range, rand() % range, rand() % range);
54    lm.Add(s, 1.0);
55  }
56  */
57  /*
58  Sphere s1(10);
59  cout << "sphere information:" << s1.GetVolume() << " " << s1.GetRadius() <<endl;
60  s1.SetOrientation(10,20,10);
61  s1.SetCenter(1,5,2);
62  lm.Add(s1,1.0);
63
64  Sphere s2(15);
65  s2.SetCenter(20,20,20);
66  lm.Add(s2,2.0);
67
68  Sphere s3(5);
69  s3.SetCenter(0,0,0);
70  lm.Add(s3,2.0);
71
72  Sphere s4(5);
73  s4.SetCenter(0,0,10);
74  lm.Add(s4,2.0);
75
76  Sphere s5(10);
77  s5.SetCenter(20,0,0);
78  lm.Add(s5,2.0);
79  */
80
81  test_calculateIQ(lm);
82}
83
84void test_calculateIQ(LORESModel &lm){
85
86  IQ iq1(10,0.001,0.3);
87  cout << "iq information:" << iq1.GetQmin() <<endl;
88
89  vector<Point3D> vp;
90  lm.GetPoints(vp);
91  WritePointsCoor(vp);
92  cout << "vp size:" <<vp.size()<<endl;
93  cout << "save into pdb file" << endl;
94  lm.OutputPDB(vp,"model.pdb");
95
96  //  for (vector<Point3D>::iterator iter = vp.begin();
97  //     iter != vp.end(); ++iter){
98  //  cout << *iter << endl;
99  //}
100
101  lm.DistDistribution(vp);
102  Array2D<double> pr(lm.GetPr());
103  //for(int i = 0; i< pr.dim1(); ++i)
104  //  cout << pr[i][0] << " " << pr[i][1] << " " << pr[i][2] << endl;
105  lm.OutputPR("test.pr");
106  cout << "pass ddfunction, and print out the pr file" <<endl;
107
108  lm.CalculateIQ(&iq1); 
109  cout <<"I(Q): \n" ;
110  //for (int i = 0; i< iq1.iq_data.dim1(); i++)
111  //  cout << iq1.iq_data[i][0]<< " " << iq1.iq_data[i][1] <<endl;
112}
113
114void test_lores2d(){
115
116  LORESModel lm(0.1);
117
118  Cylinder c1(5,20);
119  c1.SetCenter(0,0,0);
120  c1.SetOrientation(10,20,30);
121  lm.Add(c1,1.0);
122
123  vector<Point3D> vp;
124  lm.GetPoints(vp);
125
126  lm.DistDistributionXY(vp);
127  lm.OutputPR_XY("test2d.pr");
128
129  IQ iq(10,0.001,0.3);
130  lm.CalculateIQ_2D(&iq,10);
131
132  iq.OutputIQ("test2d.iq");
133}
134
135void test_lores2d_qxqy(){
136
137  LORESModel lm(0.1);
138
139  Cylinder c1(5,20);
140  c1.SetCenter(0,0,0);
141  c1.SetOrientation(10,20,30);
142  lm.Add(c1,1.0);
143
144  vector<Point3D> vp;
145  lm.GetPoints(vp);
146
147  lm.DistDistributionXY(vp); 
148
149  double aI = lm.CalculateIQ_2D(0.1,0.2);
150
151  cout << " a single I is: "<<aI<<" at Qx,Qy = 0.1,0.2" <<endl;
152}
153
154void test_GetCenter()
155{
156  LORESModel lm(0.1);
157
158  Sphere s1(10);
159  s1.SetCenter(-1,-1,-1);
160  Sphere s2(20);
161  s2.SetCenter(1,1,1);
162
163  lm.Add(s1,1.0);
164  lm.Add(s2,1.0);
165
166  vector<double> center(3);
167  center = lm.GetCenter();
168
169  cout << "center should be (0,0,0) after adding two spheres:"<<endl;
170  cout << center[0] <<" "<< center[1] <<" "<< center[2]<<endl;
171
172}
173
174void test_CalSingleI(){
175  LORESModel lm(0.1);
176
177  Cylinder cyn(10,40); 
178
179  lm.Add(cyn,1.0);
180
181  vector<Point3D> vp;
182  lm.GetPoints(vp);
183
184  lm.DistDistribution(vp);
185
186  double result = lm.CalculateIQ(0.1);
187  cout << "The I(0.1) is: " << result << endl;     
188}
189
190int main(){
191
192  printf("this\n");
193  cout << "Start" << endl;
194  //test_lores();
195  cout <<"testing DistDistributionXY"<<endl;
196  test_lores2d();
197
198  cout <<"testing GetCenter (center of the list of shapes)"<<endl;
199  test_GetCenter();
200
201  cout <<"testing calculate_2d(Qx,Qy)"<<endl;
202  test_lores2d_qxqy();
203  cout << "Pass" << endl;
204
205  cout <<"testing CalculateIQ(q)"<<endl;
206  test_CalSingleI();
207
208  return 0;
209}
Note: See TracBrowser for help on using the repository browser.