Commit d7fff826 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

changed datatype of newton options;

 changed moments in newton optimizer to const( safety reasons )
    .parallelized newton multicell optimizer.removed<iostream> from several files.Added datagenerator mode to GaussLegendreQuadrature. Parallelized
    datagenerator. Datagen works now. added safer destructor for datagen. computed initial condition for linesources with monomials
parent c1ecd6e8
Pipeline #123857 passed with stage
in 25 minutes and 18 seconds
/*!
* @file config.h
* @brief Class to handle all options and their pre and postprocessing.
* @brief: Class to handle all options and their pre and postprocessing.
* DO NOT CREATE SETTERS FOR THIS CLASS! ALL OPTIONS ARE CONSTANT (after SetPostprocessing).
*
* @author S. Schotthöfer
*
* Disclaimer: This class structure was copied and modifed with open source permission from SU2 v7.0.3 https://su2code.github.io/
* Disclaimer: This class structure was copied and (heavily) modifed with open source permission from SU2 v7.0.3 https://su2code.github.io/
*/
#ifndef CONFIG_H
......@@ -89,9 +91,9 @@ class Config
// Optimizer
OPTIMIZER_NAME _entropyOptimizerName; /*!< @brief Choice of optimizer */
double _optimizerEpsilon; /*!< @brief termination criterion epsilon for Newton Optmizer */
unsigned short _newtonIter; /*!< @brief Maximal Number of newton iterations */
unsigned long _newtonIter; /*!< @brief Maximal Number of newton iterations */
double _newtonStepSize; /*!< @brief Stepsize factor for newton optimizer */
unsigned short _newtonLineSearchIter; /*!< @brief Maximal Number of line search iterations for newton optimizer */
unsigned long _newtonLineSearchIter; /*!< @brief Maximal Number of line search iterations for newton optimizer */
bool _newtonFastMode; /*!< @brief If true, we skip the NewtonOptimizer for quadratic entropy and assign alpha = u */
// Output Options
......@@ -264,9 +266,9 @@ class Config
// Optimizer
double inline GetNewtonOptimizerEpsilon() const { return _optimizerEpsilon; }
unsigned inline GetNewtonIter() const { return _newtonIter; }
unsigned long inline GetNewtonIter() const { return _newtonIter; }
double inline GetNewtonStepSize() const { return _newtonStepSize; }
unsigned inline GetNewtonMaxLineSearches() const { return _newtonLineSearchIter; }
unsigned long inline GetNewtonMaxLineSearches() const { return _newtonLineSearchIter; }
bool inline GetNewtonFastMode() const { return _newtonFastMode; }
OPTIMIZER_NAME inline GetOptimizerName() const { return _entropyOptimizerName; }
......@@ -296,15 +298,12 @@ class Config
unsigned long inline GetTrainingDataSetSize() { return _tainingSetSize; }
// ---- Setters for option structure
// This section is dangerous
// Quadrature Structure
void SetNQuadPoints( unsigned nq ) { _nQuadPoints = nq; }
void SetNQuadPoints( unsigned nq ) { _nQuadPoints = nq; } /*! @brief Never change the nq! This is only for the test framework. */
void SetQuadName( QUAD_NAME quadName ) { _quadName = quadName; } /*! @brief Never change the quadName! This is only for the test framework. */
void SetQuadOrder( unsigned quadOrder ) { _quadOrder = quadOrder; } /*! @brief Never change the quadOrder! This is only for the test framework. */
void SetSNAllGaussPts( bool useall ) { _allGaussPts = useall; } /*! @brief Never change the this! This is only for the test framework. */
// Mesh Structure
void SetNCells( unsigned nCells ) { _nCells = nCells; }
};
#endif // CONFIG_H
......@@ -16,8 +16,8 @@ class MLOptimizer : public OptimizerBase
inline ~MLOptimizer();
void Solve( Vector& lambda, Vector& u, VectorVector& moments, unsigned idx_cell = 0 ) override;
void SolveMultiCell( VectorVector& lambda, VectorVector& u, VectorVector& moments ) override;
void Solve( Vector& lambda, Vector& u, const VectorVector& moments, unsigned idx_cell = 0 ) override;
void SolveMultiCell( VectorVector& lambda, VectorVector& u, const VectorVector& moments ) override;
private:
double* callNetwork( const unsigned input_size, double* input );
......
......@@ -18,21 +18,21 @@ class NewtonOptimizer : public OptimizerBase
~NewtonOptimizer();
void Solve( Vector& lambda, Vector& sol, VectorVector& moments, unsigned idx_cell = 0 ) override;
void SolveMultiCell( VectorVector& lambda, VectorVector& sol, VectorVector& moments ) override;
void Solve( Vector& lambda, Vector& sol, const VectorVector& moments, unsigned idx_cell = 0 ) override;
void SolveMultiCell( VectorVector& lambda, VectorVector& sol, const VectorVector& moments ) override;
/*! @brief: Computes the objective function
grad = <eta(alpha*m)> - alpha*sol */
double ComputeObjFunc( Vector& alpha, Vector& sol, VectorVector& moments );
double ComputeObjFunc( Vector& alpha, Vector& sol, const VectorVector& moments );
private:
/*! @brief: Computes gradient of objective function and stores it in grad
grad = <m*eta*'(alpha*m)> - sol */
void ComputeGradient( Vector& alpha, Vector& sol, VectorVector& moments, Vector& grad );
void ComputeGradient( Vector& alpha, Vector& sol, const VectorVector& moments, Vector& grad );
/*! @brief: Computes hessian of objective function and stores it in hessian
grad = <mXm*eta*'(alpha*m)> */
void ComputeHessian( Vector& alpha, VectorVector& moments, Matrix& hessian );
void ComputeHessian( Vector& alpha, const VectorVector& moments, Matrix& hessian );
QuadratureBase* _quadrature; /*! @brief: used quadrature */ // THis is memory doubling! Try to use a pointer.
unsigned _nq; /*! @brief: number of quadrature points */
......
......@@ -26,9 +26,9 @@ class OptimizerBase
/*! @brief : Computes the optimal Lagrange multilpiers for the dual entropy minimization problem
* @param : Vector u = pointer to vector of given moments. // Maybe use pointer for performance?
* @return : Vector alpha = optimal lagrange multipliers. Has the same length as Vector u. */
virtual void Solve( Vector& lambda, Vector& u, VectorVector& moments, unsigned idx_cell = 0 ) = 0;
virtual void Solve( Vector& lambda, Vector& u, const VectorVector& moments, unsigned idx_cell = 0 ) = 0;
virtual void SolveMultiCell( VectorVector& lambda, VectorVector& u, VectorVector& moments ) = 0;
virtual void SolveMultiCell( VectorVector& lambda, VectorVector& u, const VectorVector& moments ) = 0;
protected:
EntropyBase* _entropy; /*! @brief: Class to handle entropy functional evaluations */
......
......@@ -25,7 +25,7 @@ class nnDataGenerator
* @param: setSize: number of elements in training set
* basisSize: length of spherical harmonics basis (maybe redundant)*/
nnDataGenerator( Config* settings );
~nnDataGenerator() {}
~nnDataGenerator();
/*! @brief: computes the training data set.
* Realizable set is sampled uniformly.
......@@ -66,8 +66,10 @@ class nnDataGenerator
// IO routines
void PrintTrainingData(); /*! @brief : Print computed training data to csv file and screen */
void PrintLoadScreen(); /*! @brief: Print screen IO*/
// Helper functions
void ComputeMoments(); /*! @brief: Pre-Compute Moments at all quadrature points. */
void CheckRealizability(); // Debugging helper
};
#endif // DATAGENERATOR_H
......@@ -7,8 +7,6 @@
#ifndef CRTSNERROR_H
#define CRTSNERROR_H
#include <iostream>
#include "spdlog/spdlog.h"
class ErrorMessages
......
......@@ -264,12 +264,12 @@ void Config::SetConfigOptions() {
/*! @brief Newton Optimizer Epsilon \n DESCRIPTION: Convergencce Epsilon for Newton Optimizer \n DEFAULT 1e-3 \ingroup Config */
AddDoubleOption( "NEWTON_EPSILON", _optimizerEpsilon, 0.001 );
/*! @brief Max Iter Newton Optmizers \n DESCRIPTION: Max number of newton iterations \n DEFAULT 10 \ingroup Config */
AddUnsignedShortOption( "NEWTON_ITER", _newtonIter, 100 );
AddUnsignedLongOption( "NEWTON_ITER", _newtonIter, 100 );
/*! @brief Step Size Newton Optmizers \n DESCRIPTION: Step size for Newton optimizer \n DEFAULT 10 \ingroup Config */
AddDoubleOption( "NEWTON_STEP_SIZE", _newtonStepSize, 0.1 );
/*! @brief Max Iter for line search in Newton Optmizers \n DESCRIPTION: Max number of line search iter for newton optimizer \n DEFAULT 10 \ingroup
* Config */
AddUnsignedShortOption( "NEWTON_LINE_SEARCH_ITER", _newtonLineSearchIter, 100 );
AddUnsignedLongOption( "NEWTON_LINE_SEARCH_ITER", _newtonLineSearchIter, 100 );
/*! @brief Newton Fast mode \n DESCRIPTION: If true, we skip the Newton optimizer for Quadratic entropy and set alpha = u \n DEFAULT false
* \ingroup Config */
AddBoolOption( "NEWTON_FAST_MODE", _newtonFastMode, false );
......
......@@ -25,7 +25,7 @@ MLOptimizer::MLOptimizer( Config* settings ) : OptimizerBase( settings ) {
MLOptimizer::~MLOptimizer() { finalize_python(); }
void MLOptimizer::Solve( Vector& lambda, Vector& u, VectorVector& /*moments*/, unsigned /*idx_cell*/ ) {
void MLOptimizer::Solve( Vector& lambda, Vector& u, const VectorVector& /*moments*/, unsigned /*idx_cell*/ ) {
// Convert Vector to array
const unsigned input_size = u.size();
......@@ -49,7 +49,7 @@ void MLOptimizer::Solve( Vector& lambda, Vector& u, VectorVector& /*moments*/, u
delete[] nn_input;
}
void MLOptimizer::SolveMultiCell( VectorVector& lambda, VectorVector& u, VectorVector& /*moments*/ ) {
void MLOptimizer::SolveMultiCell( VectorVector& lambda, VectorVector& u, const VectorVector& /*moments*/ ) {
const unsigned batch_size = u.size(); // batch size = number of cells
const unsigned sol_dim = u[0].size(); // dimension of input vector = nTotalEntries
......
/*!
* @file newtonoptimizer.cpp
* @brief class for solving the minimal entropy optimization problem using a newton optimizer with line search.
* @author S. Schotthöfer
*/
#include "optimizers/newtonoptimizer.h"
#include "common/config.h"
......@@ -5,6 +10,8 @@
#include "quadratures/quadraturebase.h"
#include "toolboxes/errormessages.h"
#include <omp.h>
NewtonOptimizer::NewtonOptimizer( Config* settings ) : OptimizerBase( settings ) {
_quadrature = QuadratureBase::Create( settings );
_nq = _quadrature->GetNq();
......@@ -18,7 +25,7 @@ NewtonOptimizer::NewtonOptimizer( Config* settings ) : OptimizerBase( settings )
NewtonOptimizer::~NewtonOptimizer() { delete _quadrature; }
double NewtonOptimizer::ComputeObjFunc( Vector& alpha, Vector& sol, VectorVector& moments ) {
double NewtonOptimizer::ComputeObjFunc( Vector& alpha, Vector& sol, const VectorVector& moments ) {
double result = 0.0;
// Integrate
......@@ -29,7 +36,7 @@ double NewtonOptimizer::ComputeObjFunc( Vector& alpha, Vector& sol, VectorVector
return result;
}
void NewtonOptimizer::ComputeGradient( Vector& alpha, Vector& sol, VectorVector& moments, Vector& grad ) {
void NewtonOptimizer::ComputeGradient( Vector& alpha, Vector& sol, const VectorVector& moments, Vector& grad ) {
// Reset Vector
for( unsigned idx_sys = 0; idx_sys < grad.size(); idx_sys++ ) {
......@@ -43,7 +50,7 @@ void NewtonOptimizer::ComputeGradient( Vector& alpha, Vector& sol, VectorVector&
grad -= sol;
}
void NewtonOptimizer::ComputeHessian( Vector& alpha, VectorVector& moments, Matrix& hessian ) {
void NewtonOptimizer::ComputeHessian( Vector& alpha, const VectorVector& moments, Matrix& hessian ) {
// Reset Matrix
unsigned nSize = alpha.size();
......@@ -62,7 +69,7 @@ void NewtonOptimizer::ComputeHessian( Vector& alpha, VectorVector& moments, Matr
}
}
void NewtonOptimizer::SolveMultiCell( VectorVector& lambda, VectorVector& sol, VectorVector& moments ) {
void NewtonOptimizer::SolveMultiCell( VectorVector& lambda, VectorVector& sol, const VectorVector& moments ) {
unsigned nCells = lambda.size();
......@@ -74,12 +81,13 @@ void NewtonOptimizer::SolveMultiCell( VectorVector& lambda, VectorVector& sol, V
return;
}
#pragma omp parallel for schedule( guided )
for( unsigned idx_cell = 0; idx_cell < nCells; idx_cell++ ) {
Solve( lambda[idx_cell], sol[idx_cell], moments );
Solve( lambda[idx_cell], sol[idx_cell], moments, idx_cell );
}
}
void NewtonOptimizer::Solve( Vector& lambda, Vector& sol, VectorVector& moments, unsigned idx_cell ) {
void NewtonOptimizer::Solve( Vector& lambda, Vector& sol, const VectorVector& moments, unsigned idx_cell ) {
/* solve the problem argmin ( <eta(alpha*m)>-alpha*u))
* where alpha = Lagrange multiplier
......@@ -167,7 +175,8 @@ void NewtonOptimizer::Solve( Vector& lambda, Vector& sol, VectorVector& moments,
return;
}
}
ErrorMessages::Error( "Newton did not converge! Norm of gradient is: " + std::to_string( norm( dlambdaNew ) ) + " at cell " +
std::to_string( idx_cell ),
ErrorMessages::Error( " Newton did not converge! Norm of gradient is: " + std::to_string( norm( dlambdaNew ) ) + " at cell " +
std::to_string( idx_cell ) + ".\nObjective function value is " +
std::to_string( ComputeObjFunc( lambda, sol, moments ) ) + " .",
CURRENT_FUNCTION );
}
......@@ -299,7 +299,7 @@ void ICRU::DCSEL0( double E ) {
else if( particle == ParticleType::POSITRON )
Y[IE] = std::log( _PTCS1[IE] );
else {
std::cerr << "Unsupported particle type" << std::endl;
ErrorMessages::Error( "Unsupported particle type", CURRENT_FUNCTION );
exit( EXIT_FAILURE );
}
}
......@@ -348,7 +348,7 @@ void ICRU::SPLINE( const std::vector<double>& X,
for( unsigned I = 0; I < N1; ++I ) {
if( X[I + 1] - X[I] < 1.0e-13 ) {
std::cerr << "x values not increasing" << std::endl;
ErrorMessages::Error( "x values not increasing", CURRENT_FUNCTION );
exit( EXIT_FAILURE );
}
A[I] = X[I + 1] - X[I];
......
......@@ -211,16 +211,19 @@ VectorVector LineSource_PN::SetupIC() {
// Initial condition is dirac impulse at (x,y) = (0,0) ==> constant in angle ==> all moments - exept first - are zero.
double t = 3.2e-4; // pseudo time for gaussian smoothing (Approx to dirac impulse)
for( unsigned j = 0; j < cellMids.size(); ++j ) {
double x = cellMids[j][0];
double y = cellMids[j][1]; // (x- 0.5) * (x- 0.5)
psi[j][0] = /*sqrt( 4 * M_PI ) * */ 1.0 / ( 4.0 * M_PI * t ) * std::exp( -( x * x + y * y ) / ( 4 * t ) );
double x = cellMids[j][0];
double y = cellMids[j][1]; // (x- 0.5) * (x- 0.5)
double c = 1.0 / ( 4.0 * M_PI * t ) * std::exp( -( x * x + y * y ) / ( 4 * t ) );
if( _settings->GetSphericalBasisName() == SPHERICAL_MONOMIALS ) {
psi[j] = c * uIC / uIC[0]; // Remember scaling
}
if( _settings->GetSphericalBasisName() == SPHERICAL_HARMONICS ) {
psi[j][0] = c;
}
}
delete tempBase; // Only temporally needed
return psi;
......
......@@ -14,7 +14,8 @@ void QGaussLegendreTensorized::SetNq() {
_nq = 2 * pow( GetOrder(), 2 );
// 2d case SN solver only needs half of the sphere
if( _settings->GetSolverName() == SN_SOLVER && _settings->GetSNAllGaussPts() == false ) {
// Not used in DataGenerator Mode. (Maybe create an own Quadrature for halfpoints? This is a potential source for bugs)
if( _settings->GetDataGeneratorMode() == false && _settings->GetSolverName() == SN_SOLVER && _settings->GetSNAllGaussPts() == false ) {
_nq = pow( GetOrder(), 2 );
}
}
......@@ -58,7 +59,7 @@ void QGaussLegendreTensorized::SetPointsAndWeights() {
unsigned range = _order; // By default, use all quad points
double normalizationFactor = 1.0;
if( _settings->GetSolverName() == SN_SOLVER && _settings->GetSNAllGaussPts() == false ) {
if( _settings->GetDataGeneratorMode() == false && _settings->GetSolverName() == SN_SOLVER && _settings->GetSNAllGaussPts() == false ) {
range = std::floor( _order / 2.0 ); // comment (steffen): why do we only need half of the points:
//=> In 2D we would count everything twice. (not wrong with scaling)
normalizationFactor = 2.0;
......
......@@ -48,6 +48,7 @@ MNSolver::MNSolver( Config* settings ) : Solver( settings ) {
// Initialize and Pre-Compute Moments at quadrature points
_moments = VectorVector( _nq, Vector( _nTotalEntries, 0.0 ) );
ComputeMoments();
}
......@@ -140,7 +141,6 @@ void MNSolver::ComputeRealizableSolution( unsigned idx_cell ) {
void MNSolver::IterPreprocessing() {
// ------- Reconstruction Step ----------------
_optimizer->SolveMultiCell( _alpha, _sol, _moments );
// ------- Relizablity Reconstruction Step ----
......
......@@ -23,7 +23,6 @@ Solver::Solver( Config* settings ) {
_neighbors = _mesh->GetNeighbours();
_normals = _mesh->GetNormals();
_nCells = _mesh->GetNumCells();
_settings->SetNCells( _nCells );
// build quadrature object and store frequently used params
_quadrature = QuadratureBase::Create( settings );
......
......@@ -16,6 +16,7 @@
#include "spdlog/spdlog.h"
#include <iostream>
#include <omp.h>
nnDataGenerator::nnDataGenerator( Config* settings ) {
_settings = settings;
......@@ -29,7 +30,6 @@ nnDataGenerator::nnDataGenerator( Config* settings ) {
_quadPoints = _quadrature->GetPoints();
_weights = _quadrature->GetWeights();
_quadPointsSphere = _quadrature->GetPointsSphere();
_settings->SetNQuadPoints( _nq );
// Spherical Harmonics
if( _settings->GetSphericalBasisName() == SPHERICAL_HARMONICS && _LMaxDegree > 0 ) {
......@@ -55,6 +55,11 @@ nnDataGenerator::nnDataGenerator( Config* settings ) {
_hEntropy = std::vector<double>( _setSize, 0.0 );
}
nnDataGenerator::~nnDataGenerator() {
delete _quadrature;
delete _entropy;
}
void nnDataGenerator::computeTrainingData() {
// Prototype: Only for _LMaxDegree == 1
// Prototype: u is sampled from [0,100]
......@@ -62,6 +67,11 @@ void nnDataGenerator::computeTrainingData() {
// --- sample u ---
SampleSolutionU();
PrintLoadScreen();
// ---- Check realizability ---
CheckRealizability();
// --- compute alphas ---
_optimizer->SolveMultiCell( _alpha, _uSol, _moments );
......@@ -100,14 +110,15 @@ void nnDataGenerator::SampleSolutionU() {
}
if( _LMaxDegree == 1 ) {
// Sample points on unit sphere. (Use Lebedev quadrature)
unsigned order = 5; // is avail.
QLebedev* quad = new QLebedev( order );
// unsigned order = 5; // is avail.
double epsilon = 0.5;
QuadratureBase* quad = QuadratureBase::Create( _settings );
VectorVector qpoints = quad->GetPoints(); // carthesian coordinates.
unsigned long nq = (unsigned long)quad->GetNq();
// Allocate memory.
unsigned long setSizeU0 = _setSize;
unsigned long setSizeU1 = nq * setSizeU0 * ( setSizeU0 + 1 ) / 2;
unsigned long setSizeU1 = nq * setSizeU0 * ( setSizeU0 - 1 ) / 2;
_setSize = setSizeU1;
// REFACTOR THIS
......@@ -118,7 +129,9 @@ void nnDataGenerator::SampleSolutionU() {
// --- sample u in order 0 ---
// u_0 = <1*psi>
#pragma omp parallel for schedule( guided )
for( unsigned long idx_set = 0; idx_set < setSizeU0; idx_set++ ) {
unsigned long outerIdx = ( idx_set - 1 ) * ( idx_set ) / 2; // sum over all radii up to current
outerIdx *= nq; // in each radius step, use all quad points
......@@ -126,24 +139,22 @@ void nnDataGenerator::SampleSolutionU() {
/* order 1 has 3 elements. (omega_x, omega_y, omega_z) = omega, let u_1 = (u_x, u_y, u_z) = <omega*psi>
* Condition u_0 >= norm(u_1) */
unsigned long localIdx = 0;
double radius = 0.0;
unsigned long innerIdx = 0;
// loop over all radii
for( unsigned long idx_subset = 0; idx_subset < idx_set; idx_subset++ ) {
double radius = du0 * ( idx_subset ); // dont use radius 0
unsigned long localIdx = outerIdx + idx_subset * nq;
radius = du0 * ( idx_subset + 1 ); // dont use radius 0 ==> shift by one
localIdx = outerIdx + idx_subset * nq;
for( unsigned quad_idx = 0; quad_idx < nq; quad_idx++ ) {
unsigned long radiusIdx = localIdx + quad_idx; // gives the global index
for( unsigned long quad_idx = 0; quad_idx < nq; quad_idx++ ) {
innerIdx = localIdx + quad_idx; // gives the global index
_uSol[radiusIdx][0] = radius;
_uSol[innerIdx][0] = radius + 2 * epsilon;
// scale quadpoints with radius
_uSol[radiusIdx][1] = radius * qpoints[quad_idx][0];
_uSol[radiusIdx][2] = radius * qpoints[quad_idx][1];
_uSol[radiusIdx][3] = radius * qpoints[quad_idx][2];
std::cout << " radiusIdx: " << radiusIdx << "\n";
// std::cout << " _uSol[radiusIdx][0]: " << _uSol[radiusIdx][0] << "\n";
// std::cout << " _uSol[radiusIdx][1]: " << _uSol[radiusIdx][1] << "\n";
// std::cout << " _uSol[radiusIdx][2]: " << _uSol[radiusIdx][2] << "\n";
// std::cout << " _uSol[radiusIdx][3]: " << _uSol[radiusIdx][3] << "\n";
_uSol[innerIdx][1] = radius * qpoints[quad_idx][0];
_uSol[innerIdx][2] = radius * qpoints[quad_idx][1];
_uSol[innerIdx][3] = radius * qpoints[quad_idx][2];
}
}
}
......@@ -175,9 +186,63 @@ void nnDataGenerator::ComputeEntropyH_primal() {
void nnDataGenerator::PrintTrainingData() {
auto log = spdlog::get( "event" );
auto logCSV = spdlog::get( "tabular" );
log->info( "---------------------- Data Generation Successful ------------------------" );
std::string uSolString = "";
std::string alphaString = "";
for( unsigned idx_sys = 0; idx_sys < _nTotalEntries; idx_sys++ ) {
uSolString += "u_" + std::to_string( idx_sys ) + " , ";
alphaString += "alpha_" + std::to_string( idx_sys ) + " , ";
}
// log->info( uSolString + alphaString + " h" );
logCSV->info( uSolString + alphaString + " h" );
for( unsigned idx_set = 0; idx_set < _setSize; idx_set++ ) {
log->info( "{}, {}, {}", _uSol[idx_set][0], _alpha[idx_set][0], _hEntropy[idx_set] );
logCSV->info( "{}, {}, {}", _uSol[idx_set][0], _alpha[idx_set][0], _hEntropy[idx_set] );
std::string uSolString = "";
std::string alphaString = "";
for( unsigned idx_sys = 0; idx_sys < _nTotalEntries; idx_sys++ ) {
uSolString += std::to_string( _uSol[idx_set][idx_sys] ) + " , ";
alphaString += std::to_string( _alpha[idx_set][idx_sys] ) + " , ";
}
// log->info( uSolString + alphaString + " {}", _hEntropy[idx_set] );
logCSV->info( uSolString + alphaString + " {}", _hEntropy[idx_set] );
}
}
void nnDataGenerator::CheckRealizability() {
if( _LMaxDegree == 1 ) {
double normU1 = 0.0;
Vector u1( 3, 0.0 );
for( unsigned idx_set = 0; idx_set < _setSize; idx_set++ ) {
if( _uSol[idx_set][0] == 0 ) {
if( _uSol[idx_set][1] > 0 || _uSol[idx_set][2] > 0 || _uSol[idx_set][3] > 0 ) {
ErrorMessages::Error( "Moment not realizable [code 0].", CURRENT_FUNCTION );
}
}
else {
u1 = { _uSol[idx_set][1], _uSol[idx_set][2], _uSol[idx_set][3] };
normU1 = norm( u1 );
if( normU1 / _uSol[idx_set][0] >= 1 ) {
// std::cout << "normU1 / _uSol[" << idx_set << "][0]: " << normU1 / _uSol[idx_set][0] << "\n";
// std::cout << "normU1: " << normU1 << " | _uSol[idx_set][0] " << _uSol[idx_set][0] << "\n";
ErrorMessages::Error( "Moment not realizable [code 1].", CURRENT_FUNCTION );
}
if( normU1 / _uSol[idx_set][0] <= 0 ) {
// std::cout << "_uSol" << _uSol[idx_set][1] << " | " << _uSol[idx_set][2] << " | " << _uSol[idx_set][3] << " \n";
// std::cout << "normU1 / _uSol[" << idx_set << "][0]: " << normU1 / _uSol[idx_set][0] << "\n";
// std::cout << "normU1: " << normU1 << " | _uSol[idx_set][0] " << _uSol[idx_set][0] << "\n";
ErrorMessages::Error( "Moment not realizable [code 2].", CURRENT_FUNCTION );
}
}
}
}
}
void nnDataGenerator::PrintLoadScreen() {
auto log = spdlog::get( "event" );
log->info( "------------------------ Data Generation Starts --------------------------" );
log->info( "| Generating {} datapoints.", _setSize );
}
// changed datatype of newton options;
// changed moments in newton optimizer to const( safety reasons )
// .parallelized newton multicell optimizer.removed<iostream> from several files.Added datagenerator mode to GaussLegendreQuadrature
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment