Пример #1
0
static void print_grid(FILE *fp,real ener[],int natoms,rvec f[],rvec fshake[],
                       rvec x[],t_block *mols,real mass[],tensor pres)
{
    static bool bFirst = TRUE;
    static char *desc[] = {
        "------------------------------------------------------------------------",
        "In the output from the forcefield scan we have the potential energy,",
        "then the root mean square force on the atoms, and finally the parameters",
        "in the order they appear in the input file.",
        "------------------------------------------------------------------------"
    };
    real msf1;
    int  i;

    if (bFirst) {
        for(i=0; (i<asize(desc)); i++)
            fprintf(fp,"%s\n",desc[i]);
        fflush(fp);
        bFirst = FALSE;
    }
    if ((ff.tol == 0) || (fabs(ener[F_EPOT]/ff.nmol-ff.epot) < ff.tol)) {
        msf1 = msf(natoms,f,fshake);
        if ((ff.f_max == 0) || (msf1 < sqr(ff.f_max)))
            print_range(fp,pres,msf1,ener[F_EPOT]/ff.nmol);
    }
}
Пример #2
0
gmx_bool print_forcefield(FILE *fp, real ener[], int natoms, rvec f[], rvec fshake[],
                          rvec x[], t_block *mols, real mass[], tensor pres)
{
    real msf1;

    if (ga)
    {
        msf1 = msf(natoms, f, fshake);
        if (debug)
        {
            fprintf(fp, "Pressure: %12g, RMSF: %12g, Energy-Epot: %12g, cost: %12g\n",
                    ener[F_PRES], sqrt(msf1), ener[F_EPOT]/ff.nmol-ff.epot,
                    cost(pres, msf1, ener[F_EPOT]/ff.nmol));
        }
        if (print_ga(fp, ga, msf1, pres, scale, (ener[F_EPOT]/ff.nmol), range, ff.tol))
        {
            return TRUE;
        }
        fflush(fp);
    }
    else
    {
        print_grid(fp, ener, natoms, f, fshake, x, mols, mass, pres);
    }
    return FALSE;
}
Пример #3
0
K3b::Msf K3b::operator-( const K3b::Msf& m, int i )
{
  K3b::Msf msf(m);
  return msf -= i;
}
Пример #4
0
K3b::Msf K3b::operator-( const K3b::Msf& m1, const K3b::Msf& m2 )
{
  K3b::Msf msf(m1);
  return msf -= m2;
}
Пример #5
0
int toc_readtoc( WINDOW * win )
{
  struct _toc_data * data;
  struct idao_stream * in;
  const static char * type[] = { "Audio", "Data mode 1", "Data mode 2", "Data" };
  long beg, end;
  int m, s, f;
  int i, entry, mode;

  data = DataSearch( win, TW_MAGIC );
  if( data == NULL )
  {
    data = new_toc_data( );
    if( !data ) return -1;
  }

  busybee();

  if( toc_popup.selected == 0 )
    in = idao_open_file( toc_info.toc_file );
  else
    in = idao_open_cd( toc_popup.item[toc_popup.selected].info );
  if( !in ) goto readerr;

  data->toc = in->toc;

  /* Analyse de la toc */
  entry = get_toc_entry( &data->toc, 0xa1, data->toc.head.last_track );
  data->n_tracks = desc( data->toc, entry ).pmin;

  if( toc_gen_tree( data ) ) goto readerr2;

  for( i=0; i<data->n_tracks; i++ )
  {
    sprintf( data->f[i].tno, "%2d", i + 1 );
    beg = get_track_offset( &data->toc, i + 1, &end );
    msf( beg, &m, &s, &f );
    sprintf( data->f[i].beg_time, "%02d%02d%02d", m, s, f );
    msf( end - 1, &m, &s, &f );
    mode = get_mode( &data->toc, i + 1 );
    if( mode < 0 ) mode = 3;
    objc_enable( data->tree, i*data->n_obj + 1 + TF_CK, mode == 0 /*mode != 3*/ );
    data->tree[ i*data->n_obj + 1 + TF_TYPE ].ob_spec.free_string = type[ mode ];
    sprintf( data->f[i].end_time, "%02d%02d%02d", m, s, f );
    data->tree[ i*data->n_obj + 1 + TF_TNO ].ob_spec.free_string = data->f[i].tno;
  }
  idao_close( in );

  FormAttach( win, data->tree, form_mgr );
  DataAttach( win, TW_MAGIC, data );
  EvntAttach( win, WM_DESTROY, toc_destroy );

  wind_center( win, -1, data->tree->ob_height );
  objc_redraw( data->tree, 0 );

  arrow();
  return 0;
readerr2:
  idao_close( in );
readerr:
  free( data );
  arrow();
  alert_msg( "AL_CANTREAD", 1 );
  return -1;
}
// =============================================================================
int main(int argc, char** argv) {
  // Check arguments
  if (argc < 3) {
    std::cerr << "Usage: " << argv[0] << " NODES_FILE TETS_FILE\n";
    exit(1);
  }

  // Construct an empty graph
  GraphType graph;

  // Create a nodes_file from the first input argument
  std::ifstream nodes_file(argv[1]);
  // Interpret each line of the nodes_file as a 3D Point and add to the Graph
  Point p;
  std::vector<typename GraphType::node_type> nodes;
  while (CME212::getline_parsed(nodes_file, p))
  nodes.push_back(graph.add_node(p));

  // Create a tets_file from the second input argument
  std::ifstream tets_file(argv[2]);
  // Interpret each line of the tets_file as four ints which refer to nodes
  std::array<int,4> t;
  while (CME212::getline_parsed(tets_file, t)) {
    graph.add_edge(nodes[t[0]], nodes[t[1]]);
    graph.add_edge(nodes[t[0]], nodes[t[2]]);
    #if 1
    // Diagonal edges
    graph.add_edge(nodes[t[0]], nodes[t[3]]);
    graph.add_edge(nodes[t[1]], nodes[t[2]]);
    #endif
    graph.add_edge(nodes[t[1]], nodes[t[3]]);
    graph.add_edge(nodes[t[2]], nodes[t[3]]);
  }



  // Set initial velocity and mass
  for (GraphType::NodeIterator it = graph.node_begin(); it != graph.node_end(); ++it) {
    Node n = *it;
    n.value().vel = Point(0,0,0);       // Initial velocity == 0
    n.value().mass = 1.0 / graph.num_nodes(); // graph has total mass == 1, constant density
  }

  // Set rest length for all of the Edges to their initial length
  for (GraphType::EdgeIterator ei = graph.edge_begin(); ei != graph.edge_end(); ++ei ) {
    (*ei).value().L = (*ei).length();
  }

  // Print out the stats
  std::cout << graph.num_nodes() << " " << graph.num_edges() << std::endl;

  // Launch the SDLViewer
  CME212::SDLViewer viewer;
  auto node_map = viewer.empty_node_map(graph);
  viewer.launch();

  viewer.add_nodes(graph.node_begin(), graph.node_end(), node_map);
  viewer.add_edges(graph.edge_begin(), graph.edge_end(), node_map);

  viewer.center_view();

  // Begin the mass-spring simulation
  double dt = 0.001;
  double t_start = 0;
  double t_end = 5.0;

  for (double t = t_start; t < t_end; t += dt) {
    // P1 ---------------------------------------------------------------------
    // symp_euler_step(graph, t, dt, Problem1Force());

    // P3 ----------------------------------------------------------------------
    //symp_euler_step(graph, t, dt, cf);

    // Create individual forces
    GravityForce g(grav);
    MassSpringForce msf(100);
    DampingForce d(1.0 / graph.num_nodes());

    // Combine the individual forces
    auto cf = make_combined_force(g, msf, d);

    // P4 ----------------------------------------------------------------------
    // Create individual constraints
    HPlane hp(-0.75);
    Sphere sp(0.15, Point(0.5,0.5,-0.5));
    SphereRemove sr(0.15, Point(0.5,0.5,-0.5));

    // Combined individual constraints
    // P4.1
    // auto c = make_combined_constraint(hp, FixedConstraint());
    // P4.2
    // auto c = make_combined_constraint(sp, FixedConstraint());
    // P4.3
    auto c = make_combined_constraint(sr, FixedConstraint());
    // Mixed constraints
    // auto c = make_combined_constraint(hp, sr, FixedConstraint());
    // auto c = make_combined_constraint(hp, sp, FixedConstraint());

    symp_euler_step(graph, t, dt, cf, c);

    viewer.clear();
    node_map.clear();
    viewer.add_nodes(graph.node_begin(), graph.node_end(), node_map);
    viewer.add_edges(graph.edge_begin(), graph.edge_end(), node_map);

    // Update viewer with nodes' new positions
    viewer.add_nodes(graph.node_begin(), graph.node_end(), node_map);
    viewer.set_label(t);

    // These lines slow down the animation for small graphs, like grid0_*.
    // Feel free to remove them or tweak the constants.
    if (graph.size() < 100)
    CME212::sleep(0.0001);
  }

  return 0;
}