本文整理汇总了C++中N_VNew_Serial函数的典型用法代码示例。如果您正苦于以下问题:C++ N_VNew_Serial函数的具体用法?C++ N_VNew_Serial怎么用?C++ N_VNew_Serial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了N_VNew_Serial函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: RefSol
void RefSol(realtype tout, N_Vector yref)
{
void *cpode_mem;
N_Vector yy, yp;
realtype tol, t, th, thd;
int flag;
yy = N_VNew_Serial(2);
yp = N_VNew_Serial(2);
Ith(yy,1) = 0.0; /* theta */
Ith(yy,2) = 0.0; /* thetad */
tol = TOL_REF;
cpode_mem = CPodeCreate(CP_EXPL, CP_BDF, CP_NEWTON);
flag = CPodeSetMaxNumSteps(cpode_mem, 100000);
flag = CPodeInit(cpode_mem, (void *)fref, NULL, 0.0, yy, yp, CP_SS, tol, &tol);
flag = CPDense(cpode_mem, 2);
flag = CPodeSetStopTime(cpode_mem, tout);
flag = CPode(cpode_mem, tout, &t, yy, yp, CP_NORMAL_TSTOP);
th = Ith(yy,1);
thd = Ith(yy,2);
Ith(yref,1) = cos(th);
Ith(yref,2) = sin(th);
Ith(yref,3) = -thd*sin(th);
Ith(yref,4) = thd*cos(th);
N_VDestroy_Serial(yy);
N_VDestroy_Serial(yp);
CPodeFree(&cpode_mem);
return;
}
开发者ID:AyMaN-GhOsT,项目名称:simbody,代码行数:34,代码来源:pend_test.c
示例2: GetSol
void GetSol(void *cpode_mem, N_Vector yy0, realtype tol,
realtype tout, booleantype proj, N_Vector yref)
{
N_Vector yy, yp;
realtype t, x, y, xd, yd, g;
int flag;
long int nst, nfe, nsetups, nje, nfeLS, ncfn, netf;
if (proj) {
printf(" YES ");
CPodeSetProjFrequency(cpode_mem, 1);
} else {
CPodeSetProjFrequency(cpode_mem, 0);
printf(" NO ");
}
yy = N_VNew_Serial(4);
yp = N_VNew_Serial(4);
flag = CPodeReInit(cpode_mem, (void *)f, NULL, 0.0, yy0, NULL, CP_SS, tol, &tol);
flag = CPode(cpode_mem, tout, &t, yy, yp, CP_NORMAL_TSTOP);
x = Ith(yy,1);
y = Ith(yy,2);
g = ABS(x*x + y*y - 1.0);
N_VLinearSum(1.0, yy, -1.0, yref, yy);
N_VAbs(yy, yy);
x = Ith(yy,1);
y = Ith(yy,2);
xd = Ith(yy,3);
yd = Ith(yy,4);
printf("%9.2e %9.2e %9.2e %9.2e | %9.2e |",
Ith(yy,1),Ith(yy,2),Ith(yy,3),Ith(yy,4),g);
CPodeGetNumSteps(cpode_mem, &nst);
CPodeGetNumFctEvals(cpode_mem, &nfe);
CPodeGetNumLinSolvSetups(cpode_mem, &nsetups);
CPodeGetNumErrTestFails(cpode_mem, &netf);
CPodeGetNumNonlinSolvConvFails(cpode_mem, &ncfn);
CPDlsGetNumJacEvals(cpode_mem, &nje);
CPDlsGetNumFctEvals(cpode_mem, &nfeLS);
printf(" %6ld %6ld+%-4ld %4ld (%3ld) | %3ld %3ld\n",
nst, nfe, nfeLS, nsetups, nje, ncfn, netf);
N_VDestroy_Serial(yy);
N_VDestroy_Serial(yp);
return;
}
开发者ID:AyMaN-GhOsT,项目名称:simbody,代码行数:58,代码来源:pend_test.c
示例3: main
int main(void)
{
realtype dx, dy, reltol, abstol, t, tout, umax;
N_Vector u, up;
UserData data;
void *cvode_mem;
int iout, flag;
long int nst;
u = NULL;
data = NULL;
cvode_mem = NULL;
u = N_VNew_Serial(NEQ);
up = N_VNew_Serial(NEQ);
reltol = ZERO;
abstol = ATOL;
data = (UserData) malloc(sizeof *data);
dx = data->dx = XMAX/(MX+1);
dy = data->dy = YMAX/(MY+1);
data->hdcoef = ONE/(dx*dx);
data->hacoef = HALF/(TWO*dx);
data->vdcoef = ONE/(dy*dy);
SetIC(u, data);
cvode_mem = CPodeCreate(CP_EXPL, CP_BDF, CP_NEWTON);
flag = CPodeInit(cvode_mem, (void *)f, data, T0, u, NULL, CP_SS, reltol, &abstol);
flag = CPLapackBand(cvode_mem, NEQ, MY, MY);
flag = CPDlsSetJacFn(cvode_mem, (void *)Jac, data);
/* In loop over output points: call CPode, print results, test for errors */
umax = N_VMaxNorm(u);
PrintHeader(reltol, abstol, umax);
for(iout=1, tout=T1; iout <= NOUT; iout++, tout += DTOUT) {
flag = CPode(cvode_mem, tout, &t, u, up, CP_NORMAL);
umax = N_VMaxNorm(u);
flag = CPodeGetNumSteps(cvode_mem, &nst);
PrintOutput(t, umax, nst);
}
PrintFinalStats(cvode_mem);
N_VDestroy_Serial(u);
CPodeFree(&cvode_mem);
free(data);
return(0);
}
开发者ID:BrianZ1,项目名称:simbody,代码行数:52,代码来源:cpsbanx_lap.c
示例4: N_VNew_Serial
void OpenSMOKE_CVODE_Sundials<T>::MemoryAllocation(const int n)
{
this->n_ = n; // Number of equations
this->y0_ = new double[this->n_];
this->y_ = new double[this->n_];
y0Sundials_ = N_VNew_Serial(this->n_);
if (check_flag((void *)y0Sundials_, std::string("N_VNew_Serial"), 0)) exit(-1);
ySundials_ = N_VNew_Serial(this->n_);
if (check_flag((void *)ySundials_, std::string("N_VNew_Serial"), 0)) exit(-1);
}
开发者ID:acuoci,项目名称:laminarSMOKE,代码行数:13,代码来源:OpenSMOKE_CVODE_Sundials.hpp
示例5: N_VNew_Serial
void SundialsInterface::init_memory(void* mem) const {
Integrator::init_memory(mem);
auto m = static_cast<SundialsMemory*>(mem);
// Allocate n-vectors
m->xz = N_VNew_Serial(nx_+nz_);
m->q = N_VNew_Serial(nq_);
m->rxz = N_VNew_Serial(nrx_+nrz_);
m->rq = N_VNew_Serial(nrq_);
// Allocate memory
m->p.resize(np_);
m->rp.resize(nrp_);
}
开发者ID:RobotXiaoFeng,项目名称:casadi,代码行数:14,代码来源:sundials_interface.cpp
示例6: AllocUserData
static WebData AllocUserData(void)
{
int i, ngrp = NGRP, ns = NS;
WebData wdata;
wdata = (WebData) malloc(sizeof *wdata);
for(i=0; i < ngrp; i++) {
(wdata->P)[i] = newDenseMat(ns, ns);
(wdata->pivot)[i] = newIndexArray(ns);
}
wdata->rewt = N_VNew_Serial(NEQ+1);
wdata->vtemp = N_VNew_Serial(NEQ+1);
return(wdata);
}
开发者ID:polymec,项目名称:polymec-dev,代码行数:15,代码来源:cvsFoodWeb_ASAi_kry.c
示例7: N_VNew_Serial
void CVodesIntegrator::sensInit(double t0, FuncEval& func)
{
m_np = func.nparams();
m_sens_ok = false;
N_Vector y = N_VNew_Serial(static_cast<sd_size_t>(func.neq()));
m_yS = N_VCloneVectorArray_Serial(static_cast<sd_size_t>(m_np), y);
for (size_t n = 0; n < m_np; n++) {
N_VConst(0.0, m_yS[n]);
}
N_VDestroy_Serial(y);
int flag = CVodeSensInit(m_cvode_mem, static_cast<sd_size_t>(m_np),
CV_STAGGERED, CVSensRhsFn(0), m_yS);
if (flag != CV_SUCCESS) {
throw CanteraError("CVodesIntegrator::sensInit", "Error in CVodeSensInit");
}
vector_fp atol(m_np);
for (size_t n = 0; n < m_np; n++) {
// This scaling factor is tuned so that reaction and species enthalpy
// sensitivities can be computed simultaneously with the same abstol.
atol[n] = m_abstolsens / func.m_paramScales[n];
}
flag = CVodeSensSStolerances(m_cvode_mem, m_reltolsens, atol.data());
}
开发者ID:Niemeyer-Research-Group,项目名称:cantera,代码行数:26,代码来源:CVodesIntegrator.cpp
示例8: N_VNew_NrnParallelLD
N_Vector Cvode::nvnew(long int n) {
#if PARANEURON
if (use_partrans_) {
if (net_cvode_instance->use_long_double_) {
return N_VNew_NrnParallelLD(0, n, global_neq_);
}else{
return N_VNew_Parallel(0, n, global_neq_);
}
}
#endif
if (nctd_ > 1) {
assert(n == neq_);
if (!nthsizes_) {
nthsizes_ = new long int[nrn_nthread];
for (int i = 0; i < nrn_nthread; ++i) {
nthsizes_[i] = ctd_[i].nvsize_;
}
}
#if 1
int sum = 0;
for (int i=0; i < nctd_; ++i) { sum += nthsizes_[i];}
assert(sum == neq_);
#endif
if (net_cvode_instance->use_long_double_) {
return N_VNew_NrnThreadLD(n, nctd_, nthsizes_);
}else{
return N_VNew_NrnThread(n, nctd_, nthsizes_);
}
}
if (net_cvode_instance->use_long_double_) {
return N_VNew_NrnSerialLD(n);
}else{
return N_VNew_Serial(n);
}
}
开发者ID:nrnhines,项目名称:nrn,代码行数:35,代码来源:cvodeobj.cpp
示例9: N_VNew_Serial
void CVodesIntegrator::sensInit(double t0, FuncEval& func)
{
m_np = func.nparams();
size_t nv = func.neq();
m_sens_ok = false;
doublereal* data;
N_Vector y;
y = N_VNew_Serial(static_cast<sd_size_t>(nv));
m_yS = N_VCloneVectorArray_Serial(static_cast<sd_size_t>(m_np), y);
for (size_t n = 0; n < m_np; n++) {
data = NV_DATA_S(m_yS[n]);
for (size_t j = 0; j < nv; j++) {
data[j] =0.0;
}
}
int flag = CVodeSensInit(m_cvode_mem, static_cast<sd_size_t>(m_np),
CV_STAGGERED, CVSensRhsFn(0), m_yS);
if (flag != CV_SUCCESS) {
throw CVodesErr("Error in CVodeSensMalloc");
}
vector_fp atol(m_np, m_abstolsens);
double rtol = m_reltolsens;
flag = CVodeSensSStolerances(m_cvode_mem, rtol, atol.data());
}
开发者ID:thomasfiala,项目名称:cantera,代码行数:28,代码来源:CVodesIntegrator.cpp
示例10: N_VNew_Serial
void SundialsInterface::init_memory(void* mem) const {
Integrator::init_memory(mem);
auto m = static_cast<SundialsMemory*>(mem);
// Allocate n-vectors
m->xz = N_VNew_Serial(nx_+nz_);
m->q = N_VNew_Serial(nq_);
m->rxz = N_VNew_Serial(nrx_+nrz_);
m->rq = N_VNew_Serial(nrq_);
// Reset linear solvers
linsolF_.reset(get_function("jacF").sparsity_out(0));
if (nrx_>0) {
linsolB_.reset(get_function("jacB").sparsity_out(0));
}
}
开发者ID:andrescodas,项目名称:casadi,代码行数:16,代码来源:sundials_interface.cpp
示例11: N_VNew_Serial
int ViCaRS::init(SimEquations *eqns) {
unsigned int num_local, i;
int flag;
_eqns = eqns;
_num_equations = eqns->num_equations();
//flag = fill_greens_matrix();
//if (flag) return flag;
num_local = (unsigned int)_bdata.size();
_vars = N_VNew_Serial(_num_global_blocks*_num_equations);
if (_vars == NULL) return 1;
// Init CVodes structures
flag = _eqns->init(this);
if (flag) return flag;
for (i=0;i<_solvers.size();++i) _solvers[i]->init_solver(this);
_cur_solver = 0;
_cur_time = 0;
return 0;
}
开发者ID:eheien,项目名称:vicars,代码行数:25,代码来源:RateState.cpp
示例12: Problem2
static void Problem2(void)
{
void *fct;
void *cpode_mem;
N_Vector y, yp;
realtype reltol=RTOL, abstol=ATOL, t, tout, erm, hu;
int flag, iout, qu;
y = NULL;
yp = NULL;
cpode_mem = NULL;
y = N_VNew_Serial(P2_NEQ);
N_VConst(ZERO, y);
NV_Ith_S(y,0) = ONE;
yp = N_VNew_Serial(P2_NEQ);
if (ODE == CP_EXPL) {
fct = (void *)f2;
} else {
fct = (void *)res2;
f2(P2_T0, y, yp, NULL);
}
cpode_mem = CPodeCreate(ODE, CP_ADAMS, CP_FUNCTIONAL);
/* flag = CPodeSetInitStep(cpode_mem, 2.0e-9);*/
flag = CPodeInit(cpode_mem, fct, NULL, P2_T0, y, yp, CP_SS, reltol, &abstol);
printf("\n t max.err qu hu \n");
for(iout=1, tout=P2_T1; iout <= P2_NOUT; iout++, tout*=P2_TOUT_MULT) {
flag = CPode(cpode_mem, tout, &t, y, yp, CP_NORMAL);
if (flag != CP_SUCCESS) break;
erm = MaxError(y, t);
flag = CPodeGetLastOrder(cpode_mem, &qu);
flag = CPodeGetLastStep(cpode_mem, &hu);
printf("%10.3f %12.4le %2d %12.4le\n", t, erm, qu, hu);
}
PrintFinalStats(cpode_mem);
CPodeFree(&cpode_mem);
N_VDestroy_Serial(y);
N_VDestroy_Serial(yp);
return;
}
开发者ID:thomasklau,项目名称:simbody,代码行数:47,代码来源:cpsadamsx.c
示例13: main
int main()
{
void *fct;
void *cpode_mem;
N_Vector y, yp;
realtype reltol=RTOL, abstol=ATOL, t, tout, hu;
int flag, iout, qu;
y = NULL;
yp = NULL;
cpode_mem = NULL;
y = N_VNew_Serial(P1_NEQ);
NV_Ith_S(y,0) = TWO;
NV_Ith_S(y,1) = ZERO;
yp = N_VNew_Serial(P1_NEQ);
if (ODE == CP_EXPL) {
fct = (void *)f;
} else {
fct = (void *)res;
f(P1_T0, y, yp, NULL);
}
cpode_mem = CPodeCreate(ODE, CP_ADAMS, CP_FUNCTIONAL);
/* flag = CPodeSetInitStep(cpode_mem, 4.0e-9);*/
flag = CPodeInit(cpode_mem, fct, NULL, P1_T0, y, yp, CP_SS, reltol, &abstol);
printf("\n t x xdot qu hu \n");
for(iout=1, tout=P1_T1; iout <= P1_NOUT; iout++, tout += P1_DTOUT) {
flag = CPode(cpode_mem, tout, &t, y, yp, CP_NORMAL);
if (flag != CP_SUCCESS) break;
flag = CPodeGetLastOrder(cpode_mem, &qu);
flag = CPodeGetLastStep(cpode_mem, &hu);
printf("%10.5f %12.5le %12.5le %2d %6.4le\n", t, NV_Ith_S(y,0), NV_Ith_S(y,1), qu, hu);
}
PrintFinalStats(cpode_mem);
CPodeFree(&cpode_mem);
N_VDestroy_Serial(y);
N_VDestroy_Serial(yp);
return 0;
}
开发者ID:AyMaN-GhOsT,项目名称:simbody,代码行数:46,代码来源:cpsVanDPol_non.c
示例14: main
int main()
{
void *cpode_mem;
N_Vector yref, yy0;
realtype tol, tout;
int i, flag;
tout = 30.0;
/* Get reference solution */
yref = N_VNew_Serial(4);
RefSol(tout, yref);
/* Initialize solver */
tol = TOL;
cpode_mem = CPodeCreate(CP_EXPL, CP_BDF, CP_NEWTON);
yy0 = N_VNew_Serial(4);
Ith(yy0,1) = 1.0; /* x */
Ith(yy0,2) = 0.0; /* y */
Ith(yy0,3) = 0.0; /* xd */
Ith(yy0,4) = 0.0; /* yd */
flag = CPodeInit(cpode_mem, (void *)f, NULL, 0.0, yy0, NULL, CP_SS, tol, &tol);
flag = CPodeSetMaxNumSteps(cpode_mem, 50000);
flag = CPodeSetStopTime(cpode_mem, tout);
flag = CPodeProjDefine(cpode_mem, proj, NULL);
flag = CPDense(cpode_mem, 4);
for (i=0;i<5;i++) {
printf("\n\n%.2e\n", tol);
GetSol(cpode_mem, yy0, tol, tout, TRUE, yref);
GetSol(cpode_mem, yy0, tol, tout, FALSE, yref);
tol /= 10.0;
}
N_VDestroy_Serial(yref);
CPodeFree(&cpode_mem);
return(0);
}
开发者ID:AyMaN-GhOsT,项目名称:simbody,代码行数:41,代码来源:pend_test.c
示例15: setTolerances
void CVodesIntegrator::setTolerances(double reltol, int n, double* abstol) {
m_itol = CV_SV;
m_nabs = n;
if (n != m_neq) {
if (m_abstol) N_VDestroy_Serial(nv(m_abstol));
m_abstol = reinterpret_cast<void*>(N_VNew_Serial(n));
}
for (int i=0; i<n; i++) {
NV_Ith_S(nv(m_abstol), i) = abstol[i];
}
m_reltol = reltol;
}
开发者ID:anujg1991,项目名称:cantera,代码行数:12,代码来源:CVodesIntegrator.cpp
示例16: AllocUserData
static WebData AllocUserData(void)
{
int i, ngrp = NGRP, ns = NS;
WebData wdata;
wdata = (WebData) malloc(sizeof *wdata);
for(i=0; i < ngrp; i++) {
(wdata->P)[i] = denalloc(ns);
(wdata->pivot)[i] = denallocpiv(ns);
}
wdata->rewt = N_VNew_Serial(NEQ+1);
return(wdata);
}
开发者ID:igemsoftware,项目名称:USTC-Software_2011,代码行数:13,代码来源:cvakx.c
示例17: main
//main
int main(int argc, char **argv){
int i, j, n, pv=0;
char* file_name;
cs *jac;
N_Vector u;
Gen *gens;
double *u0;
//load ps file, populate ps, and grab some data
if(argc > 1)
file_name = argv[1];
else{
printf("Please specify PS data file.");
return 1;
}
PS ps=GetPS(file_name);
if(ps==NULL){
printf("Unable to build PS data.\n");
return 1;
}
n=(ps->num_buses-1)<<1;
gens=ps->gens;
u=N_VNew_Serial(n);
u0=NV_DATA_S(u);
//create an initial condition
if(gens[pv].index==ps->swing_bus)pv++;
for(i=0;i<ps->ybus->n;i++){
if(i==ps->swing_bus) continue;
j=(i>ps->swing_bus?(i-1)<<1:i<<1);
if(gens[pv].index==i){
u0[j]=0.1;
u0[j+1]=0.1;
pv++;
if(pv<ps->num_gens&&gens[pv].index==ps->swing_bus)pv++;
continue;
}
u0[j]=1.0; u0[j+1]=0.1;
}
//numerically evaluate the jacobian at initial condition
jac=CheckDerivativeN(n, n, ComputeF, u, (void*)ps);
cs_di_print(jac, 0);
//free memory and return
N_VDestroy_Serial(u);
return 0;
}
开发者ID:phines,项目名称:cosmic,代码行数:51,代码来源:sandbox.c
示例18: N_VDestroy_Serial
void CVodesIntegrator::setTolerances(double reltol, size_t n, double* abstol)
{
m_itol = CV_SV;
m_nabs = n;
if (n != m_neq) {
if (m_abstol) {
N_VDestroy_Serial(m_abstol);
}
m_abstol = N_VNew_Serial(static_cast<sd_size_t>(n));
}
for (size_t i=0; i<n; i++) {
NV_Ith_S(m_abstol, i) = abstol[i];
}
m_reltol = reltol;
}
开发者ID:thomasfiala,项目名称:cantera,代码行数:15,代码来源:CVodesIntegrator.cpp
示例19: NewVector
N_Vector NewVector(long int n)
{
N_Vector v;
long int nlocal, nglobal;
if (sundials_VecType == 1) {
v = N_VNew_Serial((long int)n);
} else {
nlocal = n;
MPI_Allreduce(&nlocal, &nglobal, 1, MPI_INT, MPI_SUM, sundials_comm);
v = N_VNew_Parallel(sundials_comm, nlocal, nglobal);
}
return(v);
}
开发者ID:OpenModelica,项目名称:OMCompiler-3rdParty,代码行数:19,代码来源:nvm_parallel.c
示例20: malloc
N_Vector *N_VNewVectorArray_Serial(int count, long int length)
{
N_Vector *vs;
int j;
if (count <= 0) return(NULL);
vs = (N_Vector *) malloc(count * sizeof(N_Vector));
if(vs == NULL) return(NULL);
for (j=0; j<count; j++) {
vs[j] = N_VNew_Serial(length);
if (vs[j] == NULL) {
N_VDestroyVectorArray_Serial(vs, j-1);
return(NULL);
}
}
return(vs);
}
开发者ID:bhache,项目名称:pkg-neuron,代码行数:20,代码来源:nvector_serial.c
注:本文中的N_VNew_Serial函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论