Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cross section tables which vary by flavor #30

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/xsections/csms_neutron.h5
Binary file not shown.
Binary file modified data/xsections/csms_proton.h5
Binary file not shown.
42 changes: 42 additions & 0 deletions include/nuSQuIDS/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,46 @@ struct H5File{
~H5File(){ H5Fclose(id); }
operator hid_t() const{ return(id); }
};

///\brief A general RAII wrapper around an hid_t
struct H5Handle{
H5Handle():id(-1),deleter(nullptr){}
///\brief Take ownership of an hid_t
///\param id The owned HDF5 object reference
///\param deleter The HDF5 API function used to dispose of the reference
///\param desc A descriptive string used to form an error message if id is not valid
H5Handle(hid_t id, herr_t(*deleter)(hid_t), const char* desc):
id(id),deleter(deleter){
if(id<0){
if(desc)
throw std::runtime_error(std::string("Failed to ")+desc);
else
throw std::runtime_error("Failed to get HDF5 object");
}
}
H5Handle(const H5Handle&)=delete;
H5Handle(H5Handle&& other):
id(other.id),deleter(other.deleter){
other.id=-1;
}
~H5Handle(){
if(id>=0)
(*deleter)(id);
}
H5Handle& operator=(H5Handle&)=delete;
H5Handle& operator=(H5Handle&& other){
if(&other!=this){
std::swap(id,other.id);
std::swap(deleter,other.deleter);
}
return *this;
}
hid_t get() const{ return id; }
operator hid_t() const{ return id; }
private:
hid_t id;
herr_t(*deleter)(hid_t);
};

template<typename T>
struct h5Datatype{};
Expand All @@ -229,6 +269,8 @@ template<> struct h5Datatype<int>{ static hid_t type(){ return H5T_NATIVE_INT; }
template<> struct h5Datatype<unsigned int>{ static hid_t type(){ return H5T_NATIVE_UINT; }};
template<> struct h5Datatype<float>{ static hid_t type(){ return H5T_NATIVE_FLOAT; }};
template<> struct h5Datatype<double>{ static hid_t type(){ return H5T_NATIVE_DOUBLE; }};

bool h5ObjectExists(hid_t loc_id, const char* name);

template<typename DestType, typename SourceType, unsigned int Rank, typename Alloc>
void writeArrayH5(hid_t loc_id, std::string name, const marray<SourceType,Rank,Alloc>& data, unsigned int compressLevel=0){
Expand Down
301 changes: 183 additions & 118 deletions include/nuSQuIDS/xsections.h

Large diffs are not rendered by default.

Binary file not shown.
162 changes: 162 additions & 0 deletions resources/paper/fig/dsdy_tabulation.eps
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 600 300
%%EndComments
%%Page: 1 1

/SampleSpacing 16.66 def
/SampleRadius 4 def
/TableDim 12 def

/drawSample {
/f exch def
/y exch def
/x exch def

newpath
SampleRadius x add y moveto
x y SampleRadius 0 360 arc
closepath

gsave % save path
f f f setrgbcolor
fill
grestore % restore path copy
stroke
} def

/arrowhead {
/size exch def
/angle exch def
/y exch def
/x exch def

/sfront 3.5 size mul def
/sback .05 size mul def
/side 2.3 size mul def
/dangle 120 def

newpath
x sfront angle cos mul add y sfront angle sin mul add moveto
x side angle dangle add cos mul add y side angle dangle add sin mul add lineto
x sback angle 180 add cos mul add y sback angle 180 add sin mul add lineto
x side angle dangle sub cos mul add y side angle dangle sub sin mul add lineto
closepath
fill
} def

/puttext { % (string) fontsize fontname x y angle
5 1 roll % move angle before fontsize
gsave
moveto findfont exch scalefont setfont % s
rotate
gsave
dup false charpath flattenpath pathbbox % s x0 y0 x1 y1
grestore
3 -1 roll sub % s x0 x1 dy
3 1 roll sub % s dy -dx
2 div exch % s -dx/2 dy
-2 div % s -dx/2 -dy/2
rmoveto show
grestore
} def


% Traditional table

((a)) 14 /Helvetica 150 12 0 puttext

0 1 TableDim{
SampleSpacing mul 50 add
/x exch def
0 1 TableDim{
SampleSpacing mul 50 add
/y exch def
x y % put on stack for drawSample
x y gt {
1
} {
0
} ifelse
drawSample
} for
} for

% E_in axis
newpath
40 40 moveto
40 260 lineto
stroke
40 255 90 2 arrowhead

(E) 12 /Helvetica 28 142 90 puttext
(in) 8 /Helvetica 32 150 90 puttext

% y axis
newpath
40 40 moveto
260 40 lineto
stroke
255 40 0 2 arrowhead

(E) 12 /Helvetica 144 32 0 puttext
(out) 8 /Helvetica 154 28 0 puttext


% New-fangled table

((b)) 14 /Helvetica 450 12 0 puttext

0 1 TableDim{
/col exch def
col SampleSpacing mul 350 add
/x exch def
0 1 TableDim{
/row exch def
row SampleSpacing mul 50 add
/y exch def
x y
1 row gt {
1
} {
TableDim col eq {
0.7
} {
0
} ifelse
} ifelse
drawSample
} for
} for

% E_in axis
newpath
340 40 moveto
340 260 lineto
stroke
340 255 90 2 arrowhead

(E) 12 /Helvetica 328 142 90 puttext
(in) 8 /Helvetica 332 150 90 puttext

% z axis
newpath
340 40 moveto
560 40 lineto
stroke
555 40 0 2 arrowhead

(z) 12 /Helvetica 450 32 0 puttext

% Key

75 275 0 drawSample
(Regular Entry) 12 /Helvetica 125 277 0 puttext

215 275 1 drawSample
(Unphysical/Unused) 12 /Helvetica 275 277 0 puttext

375 275 0.7 drawSample
(Replaced w/ Approximation) 12 /Helvetica 460 277 0 puttext

showpage
%%Trailer
Loading