source: trunk/source/processes/electromagnetic/adjoint/src/G4AdjointCSMatrix.cc @ 1315

Last change on this file since 1315 was 1228, checked in by garnier, 15 years ago

update geant4.9.3 tag

File size: 6.5 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26// $Id: G4AdjointCSMatrix.cc,v 1.4 2009/11/20 10:31:20 ldesorgh Exp $
27// GEANT4 tag $Name: geant4-09-03 $
28//
29
30#include "G4AdjointCSMatrix.hh"
31#include <iomanip>
32#include <fstream>
33#include "G4AdjointInterpolator.hh"
34///////////////////////////////////////////////////////
35//
36G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aBool){
37        theLogPrimEnergyVector.clear();
38        theLogCrossSectionVector.clear();
39        theLogSecondEnergyMatrix.clear();
40        theLogProbMatrix.clear();
41        theLogProbMatrixIndex.clear();
42        log0Vector.clear();
43        nb_of_PrimEnergy=0;
44        is_scat_proj_to_proj_case  =aBool;
45}
46///////////////////////////////////////////////////////
47//
48G4AdjointCSMatrix::~G4AdjointCSMatrix(){
49        theLogPrimEnergyVector.clear();
50        theLogCrossSectionVector.clear();
51        theLogSecondEnergyMatrix.clear();
52        theLogProbMatrix.clear();
53}
54///////////////////////////////////////////////////////
55//
56void G4AdjointCSMatrix::Clear()
57{
58        theLogPrimEnergyVector.clear();
59        theLogCrossSectionVector.clear();
60        theLogSecondEnergyMatrix.clear();
61        theLogProbMatrix.clear();
62        theLogProbMatrixIndex.clear();
63        log0Vector.clear();
64        nb_of_PrimEnergy=0;
65}
66///////////////////////////////////////////////////////
67//
68 void G4AdjointCSMatrix::AddData(G4double aLogPrimEnergy,G4double aLogCS, std::vector< double>* aLogSecondEnergyVector,
69                                                                       std::vector< double>* aLogProbVector,size_t n_pro_decade){
70       
71        G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance();
72       
73        //At this time we consider that the energy is increasing monotically
74        theLogPrimEnergyVector.push_back(aLogPrimEnergy);
75        theLogCrossSectionVector.push_back(aLogCS);
76        theLogSecondEnergyMatrix.push_back(aLogSecondEnergyVector);
77        theLogProbMatrix.push_back(aLogProbVector);
78       
79        std::vector< size_t>* aLogProbVectorIndex = 0;
80        dlog =0;
81       
82        if (n_pro_decade > 0 && aLogProbVector->size()>0) {
83                aLogProbVectorIndex = new std::vector< size_t>();
84                dlog=std::log(10.)/n_pro_decade;
85                G4double log_val = int(std::min((*aLogProbVector)[0],aLogProbVector->back())/dlog)*dlog;
86                log0Vector.push_back(log_val);
87               
88                while(log_val<0.) {
89                        aLogProbVectorIndex->push_back(theInterpolator->FindPosition(log_val,(*aLogProbVector)));
90                        log_val+=dlog;
91                } 
92        }
93        else {
94                log0Vector.push_back(0.);
95        }
96        theLogProbMatrixIndex.push_back(aLogProbVectorIndex);
97       
98       
99        nb_of_PrimEnergy++;
100       
101       
102}
103///////////////////////////////////////////////////////
104//
105G4bool G4AdjointCSMatrix::GetData(unsigned int i, G4double& aLogPrimEnergy,G4double& aLogCS,G4double& log0, std::vector< double>*& aLogSecondEnergyVector,
106                                                                       std::vector< double>*& aLogProbVector, std::vector< size_t>*& aLogProbVectorIndex)
107{       if (i>= nb_of_PrimEnergy) return false;
108        //G4cout<<"Test Get Data "<<G4endl;
109        aLogPrimEnergy = theLogPrimEnergyVector[i];
110        aLogCS = theLogCrossSectionVector[i];
111        aLogSecondEnergyVector = theLogSecondEnergyMatrix[i];
112        aLogProbVector = theLogProbMatrix[i];
113        aLogProbVectorIndex = theLogProbMatrixIndex[i];
114        log0=log0Vector[i];
115        return true;
116       
117}
118///////////////////////////////////////////////////////
119//
120void G4AdjointCSMatrix::Write(G4String file_name)
121{       std::fstream FileOutput(file_name, std::ios::out);                       
122        FileOutput<<std::setiosflags(std::ios::scientific);
123        FileOutput<<std::setprecision(6);
124        FileOutput<<theLogPrimEnergyVector.size()<<G4endl;
125        for (size_t i=0;i<theLogPrimEnergyVector.size();i++){
126                FileOutput<<std::exp(theLogPrimEnergyVector[i])/MeV<<'\t'<<std::exp(theLogCrossSectionVector[i])<<G4endl;
127                size_t j1=0;
128                FileOutput<<theLogSecondEnergyMatrix[i]->size()<<G4endl;
129                for (size_t j=0;j<theLogSecondEnergyMatrix[i]->size();j++){
130                        FileOutput<<std::exp((*theLogSecondEnergyMatrix[i])[j]);
131                        j1++;
132                        if (j1<10) FileOutput<<'\t';
133                        else  {
134                                FileOutput<<G4endl;
135                                j1=0;
136                        }       
137                }
138                if (j1>0) FileOutput<<G4endl;
139                j1=0;
140                FileOutput<<theLogProbMatrix[i]->size()<<G4endl;
141                for (size_t j=0;j<theLogProbMatrix[i]->size();j++){
142                        FileOutput<<std::exp((*theLogProbMatrix[i])[j]);
143                        j1++;
144                        if (j1<10) FileOutput<<'\t';
145                        else  {
146                                FileOutput<<G4endl;
147                                j1=0;
148                        }       
149                }
150                if (j1>0) FileOutput<<G4endl;
151               
152               
153        }
154       
155}
156///////////////////////////////////////////////////////
157//
158void G4AdjointCSMatrix::Read(G4String file_name)
159{       std::fstream FileOutput(file_name, std::ios::in);
160        size_t n1,n2;
161       
162       
163        theLogPrimEnergyVector.clear();
164        theLogCrossSectionVector.clear();
165        theLogSecondEnergyMatrix.clear();
166        theLogProbMatrix.clear();
167        FileOutput>>n1;
168        for (size_t i=0; i<n1;i++){
169                G4double E,CS;
170                FileOutput>>E>>CS;
171                theLogPrimEnergyVector.push_back(E);
172                theLogCrossSectionVector.push_back(CS);
173                FileOutput>>n2;
174                theLogSecondEnergyMatrix.push_back(new std::vector<G4double>());
175                theLogProbMatrix.push_back(new std::vector<G4double>());
176               
177                for (size_t j=0; j<n2;j++){
178                        G4double E1;
179                        FileOutput>>E1;
180                        theLogSecondEnergyMatrix[i]->push_back(E1);
181                }
182                FileOutput>>n2;
183                for (size_t j=0; j<n2;j++){
184                        G4double prob;
185                        FileOutput>>prob;
186                        theLogProbMatrix[i]->push_back(prob);
187                }
188               
189               
190               
191        }
192       
193                                 
194       
195       
196}
Note: See TracBrowser for help on using the repository browser.