def test_points_v01(): mat = N.arange(12, dtype='d').reshape(3, 4) print('Input matrix (numpy)') print(mat) print() # # Create transformations # points = C.Points(mat) identity = C.Identity() identity.identity.source(points.points.points) res = identity.identity.target.data() dt = identity.identity.target.datatype() # # Dump # print('Eigen dump (C++)') identity.dump() print() print('Points output') print(points.points.points.data()) print('Result (C++ Data to numpy)') print(res, res.dtype) print() print('Datatype:', str(dt)) assert N.allclose(mat, res), "C++ and Python results doesn't match"
def test_points_v02(): arr = N.arange(12, dtype=context.current_precision_short()) points = C.Points(arr) identity = C.Identity() points >> identity out = identity.single() for i in range(arr.size): points.set(arr, i) assert (out.data() == arr[:i]).all()
def build(self): for idx in self.nidx: reac, = idx.current_values() name = "snf_correction" + idx.current_format() try: _snf_energy, _snf_spectra = list( map(C.Points, self.snf_raw_data[reac])) except KeyError: # U238 doesn't have offequilibrium correction so just pass 1. _snf_energy, _snf_spectra = list( map(C.Points, self.snf_raw_data['average'])) _snf_energy.points.setLabel( "Original energies for SNF spectrum of {}".format(reac)) snf_spectra = C.InterpLinear( labels='Correction for spectra in {}'.format(reac)) snf_spectra.set_overflow_strategy( R.GNA.Interpolation.Strategy.Constant) snf_spectra.set_underflow_strategy( R.GNA.Interpolation.Strategy.Constant) insegment = snf_spectra.transformations.front() insegment.setLabel("Segments") interpolator_trans = snf_spectra.transformations.back() interpolator_trans.setLabel( "Interpolated SNF correction for {}".format(reac)) passthrough = C.Identity( labels="Nominal spectra for {}".format(reac)) _snf_energy >> (insegment.edges, interpolator_trans.x) _snf_spectra >> interpolator_trans.y self.set_input('snf_correction', idx, (insegment.points, interpolator_trans.newx), argument_number=0) self.set_input('snf_correction', idx, (passthrough.single_input()), argument_number=1) snap = C.Snapshot( passthrough.single(), labels='Snapshot of nominal spectra for SNF in {}'.format( reac)) product = C.Product( outputs=[snap.single(), interpolator_trans.single()], labels='Product of nominal spectrum to SNF correction in {}'. format(reac)) par_name = "snf_scale" self.reqparameter(par_name, idx, central=1., relsigma=1, labels="SNF norm for reactor {0}".format(reac)) outputs = [product.single()] weights = ['.'.join((par_name, idx.current_format()))] with self.namespace: final_sum = C.WeightedSum( weights, outputs, labels='SNF spectrum from {0} reactor'.format(reac)) self.context.objects[name] = final_sum self.set_output("snf_correction", idx, final_sum.single())
def build(self): for idx in self.nidx.iterate(): if 'isotope' in idx.names()[0]: iso, reac = idx.current_values() else: reac, iso = idx.current_values() name = "offeq_correction." + idx.current_format() try: _offeq_energy, _offeq_spectra = list(map(C.Points, self.offeq_raw_spectra[iso])) _offeq_energy.points.setLabel("Original energies for offeq spectrum of {}".format(iso)) except KeyError: # U238 doesn't have offequilibrium correction so just pass 1. if iso != 'U238': raise passthrough = C.Identity(labels='Nominal {0} spectrum in {1} reactor'.format(iso, reac)) self.context.objects[name] = passthrough dummy = C.Identity() #just to serve 1 input self.set_input('offeq_correction', idx, dummy.single_input(), argument_number=0) self.set_input('offeq_correction', idx, passthrough.single_input(), argument_number=1) self.set_output("offeq_correction", idx, passthrough.single()) continue offeq_spectra = C.InterpLinear(labels='Correction for {} spectra'.format(iso)) offeq_spectra.set_overflow_strategy(R.GNA.Interpolation.Strategy.Constant) offeq_spectra.set_underflow_strategy(R.GNA.Interpolation.Strategy.Constant) insegment = offeq_spectra.transformations.front() insegment.setLabel("Offequilibrium segments") interpolator_trans = offeq_spectra.transformations.back() interpolator_trans.setLabel("Interpolated spectral correction for {}".format(iso)) passthrough = C.Identity(labels="Nominal {0} spectrum in {1} reactor".format(iso, reac)) _offeq_energy >> (insegment.edges, interpolator_trans.x) _offeq_spectra >> interpolator_trans.y # Enu self.set_input('offeq_correction', idx, (insegment.points, interpolator_trans.newx), argument_number=0) # Anue spectra self.set_input('offeq_correction', idx, ( passthrough.single_input()), argument_number=1) par_name = "offeq_scale" self.reqparameter(par_name, idx, central=1., relsigma=0.3, labels="Offequilibrium norm for reactor {1} and iso " "{0}".format(iso, reac)) self.reqparameter("dummy_scale", idx, central=1, fixed=True, labels="Dummy weight for reactor {1} and iso " "{0} for offeq correction".format(iso, reac)) snap = C.Snapshot(passthrough.single(), labels='Snapshot of {} spectra in reac {}'.format(iso, reac)) prod = C.Product(labels='Product of initial {} spectra and ' 'offequilibrium corr in {} reactor'.format(iso, reac)) prod.multiply(interpolator_trans.single()) prod.multiply(snap.single()) outputs = [passthrough.single(), prod.single()] weights = ['.'.join(("dummy_scale", idx.current_format())), '.'.join((par_name, idx.current_format()))] with self.namespace: final_sum = C.WeightedSum(weights, outputs, labels='Corrected to offequilibrium ' '{0} spectrum in {1} reactor'.format(iso, reac)) self.context.objects[name] = final_sum self.set_output("offeq_correction", idx, final_sum.single())
mat = N.matrix(N.arange(16.0).reshape(4, 4)) print('Raw matrix') print(mat) print('Sum over rows') print(mat.A.sum(axis=0)) print('Raw normalized matrix') print(mat.A / mat.A.sum(axis=0)) pmat = C.Points(mat) rd = R.RenormalizeDiag(opts.ndiag, int(opts.offdiag), int(opts.upper)) rd.renorm.inmat(pmat.points) idt = C.Identity() idt.identity.source(rd.renorm.outmat) idt0 = C.Identity() idt0.identity.source(pmat.points) idt.identity.target.data() idt0.identity.target.data() if opts.upper: print('Upper triangle mode') print('Input (Eigen)') idt0.dump() print('Output (Eigen)')