Example #1
0
const Vector2D Curl(const Vector2D &v)
{
  Vector2D result;

#ifdef CHECK
  int msg_pos = msg_stack.push("Curl( Vector2D )");
#endif

  // Get covariant components of v
  Vector2D vco = v;
  vco.to_covariant();

  // get components (curl(v))^j

  result.x = (DDY(vco.z) - DDZ(vco.y))/J;
  result.y = (DDZ(vco.x) - DDX(vco.z))/J;
  result.z = (DDX(vco.y) - DDY(vco.x))/J;
  
  if(ShiftXderivs) {
    result.z -= ShiftTorsion*vco.z / J;
  }

  result.covariant = false; // result is contravariant
#ifdef CHECK
  msg_stack.pop(msg_pos);
#endif
  return result;
}
Example #2
0
bool Datafile::write(const string &filename, bool append)
{
  if(!enabled)
    return true; // Just pretend it worked
  
  // Record starting time
  real tstart = MPI_Wtime();

  if(!file->openw(filename, append))
    return false;

  if(!file->is_valid())
    return false;
  
  file->setRecord(-1); // Latest record

  // Write integers
  for(std::vector< VarStr<int> >::iterator it = int_arr.begin(); it != int_arr.end(); it++) {
    if(it->grow) {
      file->write_rec(it->ptr, it->name);
    }else {
      file->write(it->ptr, it->name);
    }
  }
  
  // Write reals
  for(std::vector< VarStr<real> >::iterator it = real_arr.begin(); it != real_arr.end(); it++) {
    if(it->grow) {
      file->write_rec(it->ptr, it->name);
    }else {
      file->write(it->ptr, it->name);
    }
  }

  // Write 2D fields
  
  for(std::vector< VarStr<Field2D> >::iterator it = f2d_arr.begin(); it != f2d_arr.end(); it++) {
    write_f2d(it->name, it->ptr, it->grow);
  }

  // Write 3D fields
  
  for(std::vector< VarStr<Field3D> >::iterator it = f3d_arr.begin(); it != f3d_arr.end(); it++) {
    write_f3d(it->name, it->ptr, it->grow);
  }
  
  // 2D vectors
  
  for(std::vector< VarStr<Vector2D> >::iterator it = v2d_arr.begin(); it != v2d_arr.end(); it++) {
    if(it->covar) {
      // Writing covariant vector
      Vector2D v  = *(it->ptr);
      v.to_covariant();
      
      write_f2d(it->name+string("_x"), &(v.x), it->grow);
      write_f2d(it->name+string("_y"), &(v.y), it->grow);
      write_f2d(it->name+string("_z"), &(v.z), it->grow);
    }else {
      // Writing contravariant vector
      Vector2D v  = *(it->ptr);
      v.to_contravariant();
      
      write_f2d(it->name+string("x"), &(v.x), it->grow);
      write_f2d(it->name+string("y"), &(v.y), it->grow);
      write_f2d(it->name+string("z"), &(v.z), it->grow);
    }
  }

  // 3D vectors
  
  for(std::vector< VarStr<Vector3D> >::iterator it = v3d_arr.begin(); it != v3d_arr.end(); it++) {
    if(it->covar) {
      // Writing covariant vector
      Vector3D v  = *(it->ptr);
      v.to_covariant();
      
      write_f3d(it->name+string("_x"), &(v.x), it->grow);
      write_f3d(it->name+string("_y"), &(v.y), it->grow);
      write_f3d(it->name+string("_z"), &(v.z), it->grow);
    }else {
      // Writing contravariant vector
      Vector3D v  = *(it->ptr);
      v.to_contravariant();
      
      write_f3d(it->name+string("x"), &(v.x), it->grow);
      write_f3d(it->name+string("y"), &(v.y), it->grow);
      write_f3d(it->name+string("z"), &(v.z), it->grow);
    }
  }

  file->close();

  wtime += MPI_Wtime() - tstart;

  return true;
}