//////////////////////////////////////////////////////////////////////////////// // // // This file is part of NCrystal (see https://mctools.github.io/ncrystal/) // // // // Copyright 2015-2022 NCrystal developers // // // // Licensed under the Apache License, Version 2.0 (the "License"); // // you may not use this file except in compliance with the License. // // You may obtain a copy of the License at // // // // http://www.apache.org/licenses/LICENSE-2.0 // // // // Unless required by applicable law or agreed to in writing, software // // distributed under the License is distributed on an "AS IS" BASIS, // // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // // limitations under the License. // // // //////////////////////////////////////////////////////////////////////////////// #include "NCrystal/internal/NCRomberg.hh" #include "NCrystal/internal/NCMath.hh" #include void NCrystal::Romberg::evalFuncMany(double* fvals, unsigned n, double offset, double delta) const { double * it = &fvals[0]; double nn = n;//only cast once for ( double i = 0; i < nn; ++i ) *(it++) = evalFunc( offset + delta * i ); } double NCrystal::Romberg::evalFuncManySum(unsigned n, double offset, double delta) const { double sum = 0.0; double nn = n;//only cast once for ( double i = 0; i < nn; ++i ) sum += evalFunc( offset + delta * i ); return sum; } bool NCrystal::Romberg::accept(unsigned, double prev_estimate, double estimate,double,double) const { return ncabs(estimate-prev_estimate)<1e-8; } void NCrystal::Romberg::convergenceError(double a, double b) const { std::cout<<"NCrystal CalcError: Romberg integration did not converge. Will attempt to write" " function curve to ncrystal_romberg.txt for potential debugging purposes."< #include void NCrystal::Romberg::writeFctToFile(const std::string& filename, double a, double b, unsigned n) const { nc_assert_always(b>a); if (file_exists(filename)) { std::cout<<"NCrystal Warning: Aborting writing of "<