mirror of
https://codeberg.org/vcbferreira/NuFI_deal.ii
synced 2026-08-12 22:43:17 +02:00
eval with point_value() working
This commit is contained in:
-95
@@ -1,95 +0,0 @@
|
||||
#include "nufi/blas.h"
|
||||
#include <cblas.h>
|
||||
|
||||
namespace blas
|
||||
{
|
||||
|
||||
double dot( const size_t n, const double *x, size_t incx,
|
||||
const double *y, size_t incy )
|
||||
{
|
||||
return cblas_ddot(n,x,incx,y,incy);
|
||||
}
|
||||
|
||||
float dot( const size_t n, const float *x, size_t incx,
|
||||
const float *y, size_t incy )
|
||||
{
|
||||
return cblas_sdot(n,x,incx,y,incy);
|
||||
}
|
||||
|
||||
void axpy( size_t n, double alpha, const double *x, size_t incx,
|
||||
double *y, size_t incy )
|
||||
{
|
||||
cblas_daxpy(n,alpha,x,incx,y,incy);
|
||||
}
|
||||
|
||||
void axpy( size_t n, float alpha, const float *x, size_t incx,
|
||||
float *y, size_t incy )
|
||||
{
|
||||
cblas_saxpy(n,alpha,x,incx,y,incy);
|
||||
}
|
||||
|
||||
void scal( size_t n, double alpha, double *x, size_t incx )
|
||||
{
|
||||
cblas_dscal(n,alpha,x,incx);
|
||||
}
|
||||
|
||||
void scal( size_t n, float alpha, float *x, size_t incx )
|
||||
{
|
||||
cblas_sscal(n,alpha,x,incx);
|
||||
}
|
||||
|
||||
void copy( size_t n, const double *x, size_t incx, double *y, size_t incy )
|
||||
{
|
||||
cblas_dcopy(n,x,incx,y,incy);
|
||||
}
|
||||
|
||||
void copy( size_t n, const float *x, size_t incx, float *y, size_t incy )
|
||||
{
|
||||
cblas_scopy(n,x,incx,y,incy);
|
||||
}
|
||||
|
||||
void ger( const size_t M, const size_t N, const double alpha,
|
||||
const double *X, const size_t incX, const double *Y, const size_t incY,
|
||||
double *A, const size_t lda)
|
||||
{
|
||||
cblas_dger( CblasColMajor, M, N, alpha, X, incX, Y, incY, A, lda );
|
||||
}
|
||||
|
||||
void ger( const size_t M, const size_t N, const float alpha,
|
||||
const float *X, const size_t incX, const float *Y, const size_t incY,
|
||||
float *A, const size_t lda)
|
||||
{
|
||||
cblas_sger( CblasColMajor, M, N, alpha, X, incX, Y, incY, A, lda );
|
||||
}
|
||||
|
||||
void gemv( const char trans, size_t m, size_t n,
|
||||
double alpha, const double *a, size_t lda,
|
||||
const double *x, size_t incx, double beta,
|
||||
double *y, size_t incy )
|
||||
{
|
||||
if ( trans == 'T' || trans == 'Y' )
|
||||
{
|
||||
cblas_dgemv( CblasColMajor, CblasTrans, m, n, alpha, a, lda, x, incx, beta, y, incy );
|
||||
}
|
||||
else
|
||||
{
|
||||
cblas_dgemv( CblasColMajor, CblasNoTrans, m, n, alpha, a, lda, x, incx, beta, y, incy );
|
||||
}
|
||||
}
|
||||
|
||||
void gemv( const char trans, size_t m, size_t n,
|
||||
float alpha, const float *a, size_t lda,
|
||||
const float *x, size_t incx, float beta,
|
||||
float *y, size_t incy )
|
||||
{
|
||||
if ( trans == 'T' || trans == 'Y' )
|
||||
{
|
||||
cblas_sgemv( CblasColMajor, CblasTrans, m, n, alpha, a, lda, x, incx, beta, y, incy );
|
||||
}
|
||||
else
|
||||
{
|
||||
cblas_sgemv( CblasColMajor, CblasNoTrans, m, n, alpha, a, lda, x, incx, beta, y, incy );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+15
-36
@@ -24,31 +24,24 @@ using namespace dealii;
|
||||
double NuFISolver::eval_ftilda(unsigned int n,
|
||||
double x,
|
||||
double u,
|
||||
const double *E_coeffs) const
|
||||
const PoissonProblem<1> &poisson) const
|
||||
{
|
||||
if ( n == 0 ) return f0(x,u);
|
||||
|
||||
const size_t order = Parameters::SPLINE_ORDER;
|
||||
const size_t stride_x = 1;
|
||||
const size_t stride_t = stride_x*(Nx + order - 1);
|
||||
|
||||
double Ex;
|
||||
const double *c;
|
||||
|
||||
// We omit the initial half-step.
|
||||
|
||||
while ( --n )
|
||||
{
|
||||
x = x - Parameters::DT *u;
|
||||
c = E_coeffs + n*stride_t;
|
||||
Ex = -eval<1>(x, c);
|
||||
Ex = -eval(x, poisson);
|
||||
u = u + Parameters::DT *Ex;
|
||||
}
|
||||
|
||||
// The final half-step.
|
||||
x -= Parameters::DT*u;
|
||||
c = E_coeffs + n*stride_t;
|
||||
Ex = -eval<1>(x, c);
|
||||
Ex = -eval(x, poisson);
|
||||
u += 0.5*Parameters::DT*Ex;
|
||||
|
||||
return f0(x,u);
|
||||
@@ -57,34 +50,26 @@ double NuFISolver::eval_ftilda(unsigned int n,
|
||||
double NuFISolver::eval_f(unsigned int n,
|
||||
double x,
|
||||
double u,
|
||||
const double *E_coeffs) const
|
||||
const PoissonProblem<1> &poisson) const
|
||||
{
|
||||
if ( n == 0 ) return f0(x,u);
|
||||
|
||||
const size_t order = Parameters::SPLINE_ORDER;
|
||||
const size_t stride_x = 1;
|
||||
const size_t stride_t = stride_x*(Nx + order - 1);
|
||||
|
||||
double Ex;
|
||||
const double *c;
|
||||
|
||||
// Initial half-step.
|
||||
c = E_coeffs + n*stride_t;
|
||||
Ex = -eval<1>(x, c);
|
||||
Ex = -eval(x, poisson);
|
||||
u += 0.5*Parameters::DT * Ex;
|
||||
|
||||
while ( --n )
|
||||
{
|
||||
x = x - Parameters::DT *u;
|
||||
c = E_coeffs + n*stride_t;
|
||||
Ex = -eval<1>(x, c);
|
||||
Ex = -eval(x, poisson);
|
||||
u = u + Parameters::DT *Ex;
|
||||
}
|
||||
|
||||
// The final half-step.
|
||||
x -= Parameters::DT*u;
|
||||
c = E_coeffs + n*stride_t;
|
||||
Ex = -eval<1>(x, c);
|
||||
Ex = -eval(x, poisson);
|
||||
u += 0.5*Parameters::DT*Ex;
|
||||
|
||||
return f0(x,u);
|
||||
@@ -92,7 +77,7 @@ double NuFISolver::eval_f(unsigned int n,
|
||||
|
||||
double NuFISolver::eval_rho(const unsigned int n,
|
||||
const double x,
|
||||
const double *E_coeffs,
|
||||
const PoissonProblem<1> &poisson,
|
||||
const unsigned int Nv) const
|
||||
{
|
||||
const double dv = (Parameters::V_DOMAIN_RIGHT - Parameters::V_DOMAIN_LEFT) / Nv;
|
||||
@@ -102,7 +87,7 @@ double NuFISolver::eval_rho(const unsigned int n,
|
||||
|
||||
#pragma omp parallel for reduction (+ : integral)
|
||||
for (unsigned int i = 0; i < Nv; ++i)
|
||||
integral += eval_ftilda(n, x, v_min + i * dv, E_coeffs);
|
||||
integral += eval_ftilda(n, x, v_min + i * dv, poisson);
|
||||
|
||||
return 1.0 - integral*dv;
|
||||
}
|
||||
@@ -114,9 +99,6 @@ void NuFISolver::run()
|
||||
using std::abs;
|
||||
using std::max;
|
||||
|
||||
const size_t stride_t = Nx + order - 1;
|
||||
|
||||
std::unique_ptr<double[]> coeffs { new double[ Nt*stride_t ] {} };
|
||||
std::unique_ptr<double,decltype(std::free)*> rho { reinterpret_cast<double*>(std::aligned_alloc(64,sizeof(double)*Nx)), std::free };
|
||||
|
||||
std::vector<double> int_E_squared;
|
||||
@@ -138,13 +120,13 @@ void NuFISolver::run()
|
||||
|
||||
// compute rho
|
||||
|
||||
double dx = Parameters::SPLINE_DX;
|
||||
double dx = Parameters::CALC_DX;
|
||||
|
||||
#pragma omp parallel for
|
||||
for(size_t i = 0; i<Nx; i++)
|
||||
{
|
||||
double x = Parameters::X_DOMAIN_LEFT + i*dx;
|
||||
double ith_rho = eval_rho(it, x, coeffs.get(),Parameters::NV);
|
||||
double ith_rho = eval_rho(it, x, poisson, Parameters::NV);
|
||||
|
||||
AssertThrow(std::isfinite(ith_rho), ExcMessage("NaN detected in rho"));
|
||||
rho.get()[i] = ith_rho;
|
||||
@@ -165,15 +147,12 @@ void NuFISolver::run()
|
||||
|
||||
|
||||
// interpolate and save current field
|
||||
double* current_coeffs = coeffs.get() + it*stride_t;
|
||||
interpolate<double, Parameters::SPLINE_ORDER>(current_coeffs, sampled_potential.data());
|
||||
|
||||
|
||||
std::vector<double> E_x(Nx,0.0) ;
|
||||
#pragma omp parallel for
|
||||
for(size_t ix=0; ix<Nx; ++ix)
|
||||
{
|
||||
E_x[ix] = -eval<1>(Parameters::X_DOMAIN_LEFT+ix*dx, current_coeffs);
|
||||
E_x[ix] = -eval(Parameters::X_DOMAIN_LEFT+ix*dx, poisson);
|
||||
}
|
||||
|
||||
double timer_elapsed = timer.elapsed();
|
||||
@@ -183,12 +162,12 @@ void NuFISolver::run()
|
||||
if (it % Parameters::PLOT_FREQUENCY == 0)
|
||||
{
|
||||
std::cout << "Saving results... ";
|
||||
save_f(*this, it, coeffs.get(), Parameters::SPLINE_NX, Parameters::NV, "results/ftilda_" + std::to_string(it) + ".dat");
|
||||
save_rho(*this, it, coeffs.get(), Parameters::SPLINE_NX, "results/rho_" + std::to_string(it) + ".dat");
|
||||
save_f(*this, it, poisson, Parameters::PLOT_NX, Parameters::NV, "results/ftilda_" + std::to_string(it) + ".dat");
|
||||
save_rho(*this, it, poisson, Parameters::PLOT_NX, "results/rho_" + std::to_string(it) + ".dat");
|
||||
// save_Efield(it, coeffs.get(), 128, "results/field_" + std::to_string(it) + ".dat");
|
||||
save_space_vector(E_x, "field", it);
|
||||
|
||||
double int_val = 0.5 * integral_space_vector_squared(current_coeffs);
|
||||
double int_val = 0.5 * integral_space_vector_squared(poisson);
|
||||
int_E_squared.push_back(int_val);
|
||||
save_space_vector(int_E_squared, "electricint", it);
|
||||
std::cout << "Time since start = "<< total_time<<"\n\n";
|
||||
|
||||
+9
-11
@@ -6,11 +6,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "nufi/nufi_solver.h"
|
||||
#include "nufi/poisson_problem.h"
|
||||
#include "nufi/fields.h"
|
||||
|
||||
|
||||
void save_f( const NuFISolver &solver,
|
||||
unsigned int n,
|
||||
const double *E_coeffs,
|
||||
const PoissonProblem<1> &poisson,
|
||||
unsigned int Nx_out,
|
||||
unsigned int Nv_out,
|
||||
const std::string &filename)
|
||||
@@ -38,7 +40,7 @@ void save_f( const NuFISolver &solver,
|
||||
{
|
||||
double v = vmin + (j + 0.5)*dv;
|
||||
|
||||
double val = solver.eval_f(n, x, v, E_coeffs);
|
||||
double val = solver.eval_f(n, x, v, poisson);
|
||||
|
||||
file << val;
|
||||
|
||||
@@ -54,7 +56,7 @@ void save_f( const NuFISolver &solver,
|
||||
|
||||
void save_rho(const NuFISolver &solver,
|
||||
unsigned int n,
|
||||
const double *E_coeffs,
|
||||
const PoissonProblem<1> &poisson,
|
||||
unsigned int Nx_out,
|
||||
const std::string &filename)
|
||||
{
|
||||
@@ -69,15 +71,15 @@ void save_rho(const NuFISolver &solver,
|
||||
|
||||
for (unsigned int i = 0; i < Nx_out; ++i, xmin += dx)
|
||||
{
|
||||
double val = solver.eval_rho(n, xmin, E_coeffs);
|
||||
double val = solver.eval_rho(n, xmin, poisson);
|
||||
file << val;
|
||||
file << "\n";
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void save_Efield(unsigned int n,
|
||||
const double *E_coeffs,
|
||||
void save_Efield([[maybe_unused]]unsigned int n,
|
||||
const PoissonProblem<1> &poisson,
|
||||
unsigned int Nx_out,
|
||||
const std::string &filename)
|
||||
{
|
||||
@@ -88,17 +90,13 @@ void save_Efield(unsigned int n,
|
||||
double dx = (xmax - xmin) / Nx_out;
|
||||
|
||||
// select from E_coeffs
|
||||
const size_t stride_x = 1;
|
||||
const size_t stride_t = stride_x*(Parameters::SPLINE_NX + Parameters::SPLINE_ORDER - 1);
|
||||
const double *c;
|
||||
c = E_coeffs + n*stride_t;
|
||||
|
||||
file << Nx_out << "\n";
|
||||
file << xmin << " " << xmax << "\n";
|
||||
|
||||
for (unsigned int i = 0; i < Nx_out; ++i, xmin += dx)
|
||||
{
|
||||
double val = -eval<1>(xmin, c);
|
||||
double val = -eval(xmin, poisson);
|
||||
file << val;
|
||||
file << "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user