本文整理汇总了C++中energy函数的典型用法代码示例。如果您正苦于以下问题:C++ energy函数的具体用法?C++ energy怎么用?C++ energy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了energy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int,char** argv)
{
auto solar_system = construct_tuple(sun,jupiter,saturn,uranus,neptune);
offset(solar_system);
printf ("%.9f\n", energy(solar_system));
int n = atoi(argv[1]);
for (int i = 1; i <= n; i++)
{
advance(solar_system);
}
printf ("%.9f\n", energy(solar_system));
return 0;
}
开发者ID:qznc,项目名称:d-shootout,代码行数:19,代码来源:nbody.cpp
示例2: heartbeat
void heartbeat(struct reb_simulation* r){
if (r->t > next_output){
next_output *= 1.02;
reb_integrator_synchronize(r);
FILE* f = fopen("energy.txt","a");
double e = energy(r);
fprintf(f, "%e %.16e\n", r->t, fabs((e-e_init)/e_init));
fclose(f);
}
}
开发者ID:samshipengs,项目名称:rebound,代码行数:10,代码来源:problem.c
示例3: energy_grad_and_precond
EnergyGradAndPrecond energy_grad_and_precond(const Vector &x) const {
EnergyGradAndPrecond egpg;
egpg.energy = energy(x);
egpg.grad = grad(x);
egpg.precond = grad(x);
const int sz = x.get_size();
for (int i=0; i<sz; i++) {
egpg.precond[i] /= spring(i);
}
return egpg;
}
开发者ID:exianshine,项目名称:deft,代码行数:11,代码来源:test.cpp
示例4: problem_output
void problem_output(){
if (output_check(10000.)){
output_timing();
integrator_synchronize();
FILE* f = fopen("energy.txt","a");
double e = energy();
fprintf(f,"%e %e %e\n",t, fabs((e-e_init)/e_init), tools_megno());
fclose(f);
printf(" Y = %.3f",tools_megno());
}
}
开发者ID:quasars100,项目名称:Resonance_testing_scripts,代码行数:11,代码来源:problem.c
示例5: density
tarch::la::Vector<NUMBER_OF_EULER_UNKNOWNS, double> peanoclaw::solver::euler3d::Cell::getUnknowns() const {
tarch::la::Vector<NUMBER_OF_EULER_UNKNOWNS, double> unknowns;
unknowns[0] = density();
unknowns[1] = _data[1];
unknowns[2] = _data[2];
unknowns[3] = _data[3];
unknowns[4] = energy();
unknowns[5] = marker();
return unknowns;
}
开发者ID:unterweg,项目名称:peanoclaw,代码行数:11,代码来源:Cell.cpp
示例6: energy
int superMi::tuetee_mapping(Solid* mesh, double deltaE, double deltaT)
{
double oldEnergy = 0;
double newEnergy = 0;
int error = 0;
bool flag = false;
error = energy(mesh, &oldEnergy, TUETEE);
std::cout << "Initial Tuette energy: " << oldEnergy << std::endl;
for (int i = 0; (i < 100000) && !flag; i++){
error = gradient(mesh, TUETEE);
error = absolute_derivative(mesh);
error = update_mesh(mesh, deltaT);
error = energy(mesh, &newEnergy, TUETEE);
if (i % 1000 == 0) std::cout << i + 1 << ": " << newEnergy << std::endl;
error = check_energy_change(&oldEnergy, &newEnergy, deltaE, &flag);
}
return 0;
}
开发者ID:icemiliang,项目名称:CSE570,代码行数:20,代码来源:superMi.cpp
示例7: caller
void caller()
{
int i;
float *d;
InteractionMatrix *jMatrices;
d = (float*)malloc(sizeof(float)*3*3*15);
for (i = 0; i < 15*9; i++) d[i] = i;
jMatrices = (InteractionMatrix *)(d);
printf("d=%p,jMatrices=%p\n",d,jMatrices);
energy(jMatrices[3]);
}
开发者ID:tsarvey,项目名称:spinwaves,代码行数:11,代码来源:test1.c
示例8: main
/*
This program computes first order directional derivatives
for the helmholtz energy function */
int main(int argc, char *argv[]) {
int nf, n, j, l;
double result1, result2;
double q, jd, r;
double *x, *bv;
fprintf(stdout,"HELM-DIFF-EXAM (ADOL-C Example)\n\n");
fprintf(stdout," # of independents/10 =? \n ");
scanf("%d",&nf);
/*--------------------------------------------------------------------------*/
n = 10 * nf; /* Initilizations */
x = (double*) malloc(n*sizeof(double));
bv = (double*) malloc(n*sizeof(double));
r = 1.0/n;
for (j=0; j<n; j++) {
jd = j;
bv[j] = 0.02*(1.0+fabs(sin(jd)));
x[j] = r*sqrt(1.0+jd);
}
/*--------------------------------------------------------------------------*/
result2 = energy(n,x,bv); /* basepoint */
fprintf(stdout,"%14.6E -- energy\n",result2);
/*--------------------------------------------------------------------------*/
for (l=0; l<n; l++) /* directional derivatives */
{ x[l] = x[l]+delta;
result1 = energy(n,x,bv);
x[l] = x[l]-delta;
q = (result1-result2)/delta;
fprintf(stdout,"%3d: %14.6E, \n",l,q);
}
fprintf(stdout,"%14.6E -- energy\n",result2);
free((char*) bv);
free((char*) x);
return 0;
}
开发者ID:barak,项目名称:adolc,代码行数:44,代码来源:helm-diff-exam.cpp
示例9: convergenceCriteria
bool uhfsolve::convergenceCriteria(){
//Evaluate convergence conditions
bool condition = true;
if(iterations>5000){
condition = false;
}
if(abs(energyPrev-energy())<tolerance){
condition = false;
}
return condition;
}
开发者ID:audunsh,项目名称:FYS4411,代码行数:12,代码来源:uhfsolve.cpp
示例10: energy
//---------------------------------------------
double CpxCrvletPrtd::globalenergy()
{
double lclsum = 0;
vector< vector<int> >& c = _nx;
for(int s=0; s<c.size(); s++)
for(int w=0; w<c[s].size(); w++)
if(_owners[s][w]==mpirank())
lclsum += energy(_blocks[s][w]);
double glbsum = 0;
iC( MPI_Reduce((void*)(&lclsum), (void*)(&glbsum), 1, MPI_DOUBLE, MPI_SUM, 0, PETSC_COMM_WORLD) );
return glbsum;
}
开发者ID:JumperWang,项目名称:farsight-clone,代码行数:13,代码来源:cpxcrvletprtd.cpp
示例11: problem_init
void problem_init(int argc, char* argv[]) {
// Setup constants
integrator = WHFAST;
dt = 0.001*2.*M_PI; // initial timestep (in days)
init_boxwidth(200);
// Initial conditions
{
struct particle p = {.m=1.,.x=0,.y=0.,.z=0.,.vx=0,.vy=0.,.vz=0.};
particles_add(p);
}
{
double e = 0.999;
struct particle p = {.m=0.,.x=0.01,.y=0.,.z=0.,.vx=0,.vy=0.*sqrt((1.+e)/(1.-e)),.vz=0.};
particles_add(p);
}
tools_move_to_center_of_momentum();
//problem_additional_forces = additional_forces;
// Add megno particles
//tools_megno_init(1e-16); // N = 6 after this function call.
system("rm -f *.txt");
ei = energy();
}
void additional_forces() {
particles[1].ax += 0.12/6.;
}
double energy() {
double e_kin = 0.;
double e_pot = 0.;
struct particle pi = particles[1];
e_kin += 0.5 * (pi.vx*pi.vx + pi.vy*pi.vy + pi.vz*pi.vz);
struct particle pj = particles[0];
double dx = pi.x - pj.x;
double dy = pi.y - pj.y;
double dz = pi.z - pj.z;
e_pot -= G*pj.m/sqrt(dx*dx + dy*dy + dz*dz);
return e_kin +e_pot;
}
int no =0;
void problem_output() {
no++;
// printf("%d\n", no);
if (output_check(1000.*dt)) {
output_timing();
}
// FILE* f = fopen("Y.txt","a+");
// fprintf(f,"%e %e %e\n",t,(energy()-ei)/ei,tools_megno());
// fclose(f);
}
开发者ID:quasars100,项目名称:Resonance_testing_scripts,代码行数:52,代码来源:problem.c
示例12: moveVertex
CoordType SpatialModelMaximalRepulsion3D<CoordType>::computeBeta()
{
const int n = 100;
const int numPoints = this->getHardcoreDistances().getSize();
const CoordType maxRadius = this->getTriMesh().equivalentRadius() / 50.0;
RandomGenerator& randomGenerator = this->getRandomGenerator();
Vertices<CoordType> vertices1;
Vertices<CoordType> vertices2;
CoordType sumDelta = 0.0;
for (int i = 0; i < n; ++i)
{
vertices1 = SpatialModelHardcoreDistance3D<CoordType>::drawSample( numPoints );
vertices2 = vertices1;
vertices2.detach();
int v = randomGenerator.uniformL( numPoints );
moveVertex( vertices2, v, maxRadius );
sumDelta += fabs( energy(vertices1) - energy(vertices2) );
}
return log( 20.0 ) / ( sumDelta/n );
}
开发者ID:jarpon,项目名称:epitraits,代码行数:22,代码来源:spatialmodelmaximalrepulsion3d.cpp
示例13: TEST
TEST(podio, Basics) {
auto store = podio::EventStore();
// Adding
auto& collection = store.create<ExampleHitCollection>("name");
auto hit1 = collection.create(0.,0.,0.,0.); //initialize w/ value
auto hit2 = collection.create(); //default initialize
hit2.energy(12.5);
// Retrieving
const ExampleHitCollection* coll2(nullptr);
bool success = store.get("name",coll2);
const ExampleHitCollection* coll3(nullptr);
if (store.get("wrongName",coll3) != false) success = false;
EXPECT_EQ(true, success);
}
开发者ID:roelaaij,项目名称:podio,代码行数:14,代码来源:unittest.cpp
示例14: energy_wrapped
static PyObject *
energy_wrapped(PyObject *self, PyObject *args)
{
float mass, e;
if (!PyArg_ParseTuple(args, "f:energy", &mass))
{
return NULL;
}
e = energy(mass);
return Py_BuildValue("f", e);
}
开发者ID:PlamenStilyianov,项目名称:Python,代码行数:14,代码来源:fancy_science_solution.c
示例15: main
int main(int argc, char **argv){
double* q_x = calloc(2, sizeof(double));
double* q_y = calloc(2, sizeof(double));
printf("Intial position in x : ");
scanf("%lf",&q_x[0]);
printf("Intial velocity in y : ");
scanf("%lf",&q_y[1]);
FILE *f = fopen("output.txt","w");
FILE *f_1 = fopen("out3.txt","w");
//q_x[0] = 1.0; // position
q_x[1] = 0.0; // momentum
q_y[0] = 0.0;
//q_y[1] = 1.0;
int n = 10000;
double h = (2*PI)/n;
double int_E = energy(sqrt(pow(q_x[0],2) + pow(q_y[0],2)),q_x[1],q_y[1]);
double int_L = angular_momentum(q_x[0],q_y[0],q_x[1],q_y[1]);
fprintf(f,"x \t y \t R \n");
fprintf(f_1,"%s \t %s \t %s \t %s \t %s\n","Time","E","L","Deviation in E","Deviation in L");
for (int i = 0;i<=n;i++){
double radius = sqrt(pow(q_x[0],2) + pow(q_y[0],2));
double theta = atan2(q_y[0],q_x[0]);
double E = energy(radius,q_x[1],q_y[1]);
double L = angular_momentum(q_x[0],q_y[0],q_x[1],q_y[1]);
fprintf(f,"%f \t %f \t %f\n",q_x[0] ,q_y[0],radius);
fprintf(f_1,"%.5e \t %.5e \t %.5e\t",i*h,E,L);
fprintf(f_1,"%.6e \t %.16e\n",fabs(E-int_E), fabs(L-int_L));
PERLF(q_x,force_x,h,radius);
PERLF(q_y,force_y,h,radius);
}
fclose(f);
return 0;
}
开发者ID:jpdef,项目名称:computational_physics,代码行数:37,代码来源:homework3.c
示例16: main
int main(int argc, char ** argv)
{
int n = 50000000;
int i;
clock_t t0, t1;
double r0, r1;
t0 = clock();
offset_momentum(NBODIES, bodies);
r0 = energy(NBODIES, bodies);
for (i = 1; i <= n; i++)
advance(NBODIES, bodies, 0.01);
r1 = energy(NBODIES, bodies);
t1 = clock();
printf("%.9f\n", r0);
printf("%.9f\n", r1);
printf("%f\n", ((double) (t1 - t0)) / CLOCKS_PER_SEC);
return 0;
}
开发者ID:arowM,项目名称:felix,代码行数:24,代码来源:nbody.c
示例17: setw
string Particle::toString() const {
stringstream out;
out << "Particle information" << "\n";
out << setw(30) << "energy" << setw(30) << "px" << setw(30) << "py" << setw(30) << "pz" << "\n";
out << setw(30) << energy() << setw(30) << px() << setw(30) << py() << setw(30) << pz() << "\n";
out << setw(30) << "phi" << setw(30) << "eta" << setw(30) << "theta" << setw(30) << " " << "\n";
out << setw(30) << phi() << setw(30) << eta() << setw(30) << theta() << setw(30) << " " << "\n";
out << setw(30) << "momentum" << setw(30) << "E_T" << setw(30) << "p_T" << setw(30) << " " << "\n";
out << setw(30) << momentum() << setw(30) << et() << setw(30) << pt() << setw(30) << " " << "\n";
out << setw(30) << "m_dyn" << setw(30) << "m_fix" << setw(30) << "charge" << setw(30) << " " << "\n";
out << setw(30) << massFromEnergyAndMomentum() << setw(30) << mass() << setw(30) << charge() << setw(30) << " " << "\n";
out << setw(30) << "d0 =" << setw(30) << "d0_bs" << setw(30) << " " << setw(30) << " " << "\n";
out << setw(30) << d0() << setw(30) << d0_wrtBeamSpot() << setw(30) << " " << setw(30) << " " << "\n";
return out.str();
}
开发者ID:jjacob,项目名称:AnalysisSoftware,代码行数:15,代码来源:Particle.cpp
示例18: energy
void MainWindow::imageRestore(){
for(int i = 0; i < NT; i++){
for(int j = 0; j < NT; j++){
restored[i][j] = noisy[i][j];
}
}
double beta = beta_max / (double)nbeta, d_action, naccept, nreject;
for(int count = 0; count < nbeta; count++){
for(int i = 0; i < NT; i++){
for(int j = 0; j < NT; j++){
restored[i][j] *= -1.0;
d_action = energy(i,j,beta);
restored[i][j] *= -1.0;
d_action -= energy(i,j,beta);
if(d_action > 0 || exp(d_action) > genrand()){
restored[i][j] *= -1.0;
}
}
}
beta += beta_max / (double)nbeta;
}
}
开发者ID:miaolegewang,项目名称:IRisingmodel,代码行数:24,代码来源:mainwindow.cpp
示例19: emulator
////////THE BOSS OF INTEGRATOR AND EXIT DATES//////////
int emulator(void)
{
int i,l,par_proc[size+2];
double Ttotal,time;
Ttotal = t*Num_simulation*Num_archive;
if(rank == 0) printf("\nTotal time of simulation =%lf\n\n",Ttotal);
time=0.0;
Num_par_proc_division(par_proc); //PARTICLES FOR PROCESSOR
////THIS "for" GENERATE "Num_archive" ARCHIVES WHIT POSITION AND VELOCITY
for(i=0 ; i<Num_archive ; i++)
{
for (l=0; l<Num_simulation; l++) ///NUMBER OF SIMULATION IN ONE ARCHIVE
{
if(l%10==0) energy(time,par_proc); //ENERGY CALCULATION
if(rank == 0) printf("Time of Simulation: %lf\n",time);
if(INTEGRATOR==0)
{ ////SYMPLECTIC INTEGRATION//
symplectic_integration(par_proc);
}
else if (INTEGRATOR==1)
{ ////RK4 INTEGRATION ////////
RK4_integration(par_proc);
}
else
{ ////SYMPLECTIC INTEGRATION//
symplectic_integration2(par_proc);
}
time=time + t;
}
centermasspos(par_proc); //CENTER MASS POSITIONS
centermassvel(par_proc); //CENTER MASS VELOCITIES
if(rank == 0) write_output(i); //WRITE OUTPUT ARCHIVE i-esimo
}
return 0;
}
开发者ID:eamonto,项目名称:simulacion_N_cuerpos_codigo_paralelo,代码行数:48,代码来源:integradores.c
示例20: energy
void PostureIKSolver::computeGredient(){
double energyO = energy();
gredient[0] = 0;
gredient[1] = 0;
gredient[2] = 0;
zh::Skeleton::BoneIterator bi = mSkel -> getBoneIterator();
int boneCounter = 0;
//gredient for root position
/*GoalConstIterator gi = getGoalConstIterator();
while(!gi.end()){
IKGoal goal = gi.next();
gredient[0] += 2 * (mSkel->getBone(goal.boneId)->getWorldPosition() - goal.position).x;
gredient[1] += 2 * (mSkel->getBone(goal.boneId)->getWorldPosition() - goal.position).y;
gredient[2] += 2 * (mSkel->getBone(goal.boneId)->getWorldPosition() - goal.position).z;
}*/
bi = mSkel -> getBoneIterator();
Bone* bone = bi.next();
Vector3 snap = bone ->getPosition();
bone -> setPosition(snap + Vector3(step,0,0));
gredient[0] = (energy() - energyO) / step;
bone -> setPosition(snap + Vector3(0,step,0));
gredient[1] = (energy() - energyO) / step;
bone -> setPosition(snap + Vector3(0,0,step));
gredient[2] = (energy() - energyO) / step;
bi = mSkel -> getBoneIterator();
bone -> setPosition(snap);
while(!bi.end()){
Bone* bone = bi.next();
Quat snap = bone -> getOrientation();
//x rotation
bone -> setOrientation(snap*(Quat(0,step,0,0).exp()));
gredient[boneCounter * 3 + 3] = (energy() - energyO) / step;
//y rotation
bone -> setOrientation(snap*(Quat(0,0,step,0).exp()));
gredient[boneCounter * 3 + 4] = (energy() - energyO) / step;
//z rotation
bone -> setOrientation(snap*(Quat(0,0,0,step).exp()));
gredient[boneCounter * 3 + 5] = (energy() - energyO) / step;
//reset orientation
bone -> setOrientation(snap);
boneCounter++;
}
}
开发者ID:tpejsa,项目名称:ZombieHorse,代码行数:49,代码来源:zhPostureIKSolver.cpp
注:本文中的energy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论