Go to the documentation of this file.00001 #include "MagneticField/Interpolation/src/RectangularCartesianMFGrid.h"
00002 #include "MagneticField/Interpolation/src/binary_ifstream.h"
00003 #include "MagneticField/Interpolation/src/LinearGridInterpolator3D.h"
00004
00005 #include <iostream>
00006
00007 using namespace std;
00008
00009 RectangularCartesianMFGrid::RectangularCartesianMFGrid( binary_ifstream& inFile,
00010 const GloballyPositioned<float>& vol)
00011 : MFGrid3D(vol)
00012 {
00013
00014
00015
00016
00017
00018
00019 GlobalVector localXDir(frame().toGlobal(LocalVector(1,0,0)));
00020 GlobalVector localYDir(frame().toGlobal(LocalVector(0,1,0)));
00021
00022 if (localXDir.dot(GlobalVector(1,0,0)) > 0.999999 &&
00023 localYDir.dot(GlobalVector(0,1,0)) > 0.999999) {
00024
00025 } else {
00026 cout << "ERROR: RectangularCartesianMFGrid: unexpected orientation: x: "
00027 << localXDir << " y: " << localYDir << endl;
00028 }
00029
00030 int n1, n2, n3;
00031 inFile >> n1 >> n2 >> n3;
00032 double xref, yref, zref;
00033 inFile >> xref >> yref >> zref;
00034 double stepx, stepy, stepz;
00035 inFile >> stepx >> stepy >> stepz;
00036
00037 vector<BVector> fieldValues;
00038 float Bx, By, Bz;
00039 int nLines = n1*n2*n3;
00040 fieldValues.reserve(nLines);
00041 for (int iLine=0; iLine<nLines; ++iLine){
00042 inFile >> Bx >> By >> Bz;
00043 fieldValues.push_back(BVector(Bx,By,Bz));
00044 }
00045
00046 string lastEntry;
00047 inFile >> lastEntry;
00048 if (lastEntry != "complete"){
00049 cout << "ERROR during file reading: file is not complete" << endl;
00050 }
00051
00052 GlobalPoint grefp( xref, yref, zref);
00053 LocalPoint lrefp = frame().toLocal( grefp);
00054
00055 Grid1D gridX( lrefp.x(), lrefp.x() + stepx*(n1-1), n1);
00056 Grid1D gridY( lrefp.y(), lrefp.y() + stepy*(n2-1), n2);
00057 Grid1D gridZ( lrefp.z(), lrefp.z() + stepz*(n3-1), n3);
00058 grid_ = GridType( gridX, gridY, gridZ, fieldValues);
00059
00060
00061
00062
00063
00064 }
00065
00066 void RectangularCartesianMFGrid::dump() const
00067 {
00068 cout << endl << "Dump of RectangularCartesianMFGrid" << endl;
00069
00070
00071 cout << "Number of points from Grid1D "
00072 << grid_.grida().nodes() << " " << grid_.gridb().nodes() << " " << grid_.gridc().nodes() << endl;
00073
00074
00075
00076 cout << "Reference Point from Grid1D "
00077 << grid_.grida().lower() << " " << grid_.gridb().lower() << " " << grid_.gridc().lower() << endl;
00078
00079
00080
00081 cout << "Basic Distance from Grid1D "
00082 << grid_.grida().step() << " " << grid_.gridb().step() << " " << grid_.gridc().step() << endl;
00083
00084
00085 cout << "Dumping " << grid_.data().size() << " field values " << endl;
00086
00087 }
00088
00089 MFGrid::LocalVector
00090 RectangularCartesianMFGrid::uncheckedValueInTesla( const LocalPoint& p) const
00091 {
00092
00093
00094
00095 LinearGridInterpolator3D interpol( grid_);
00096 GridType::ReturnType value = interpol.interpolate( p.x(), p.y(), p.z());
00097 return LocalVector(value);
00098 }
00099
00100 void RectangularCartesianMFGrid::toGridFrame( const LocalPoint& p,
00101 double& a, double& b, double& c) const
00102 {
00103 a = p.x();
00104 b = p.y();
00105 c = p.z();
00106 }
00107
00108 MFGrid::LocalPoint RectangularCartesianMFGrid::fromGridFrame( double a, double b, double c) const
00109 {
00110 return LocalPoint( a, b, c);
00111 }