Example #1
0
const Vector2D V_dot_Grad(const Vector2D &v, const Vector2D &a)
{
  Vector2D result;

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

  Vector2D vcn = v;
  vcn.to_contravariant();

  if(a.covariant) {
    
    result.x = VDDX(vcn.x, a.x) + VDDY(vcn.y, a.x) + VDDZ(vcn.z, a.x);
    result.x -= vcn.x*(G1_11*a.x + G2_11*a.y + G3_11*a.z);
    result.x -= vcn.y*(G1_12*a.x + G2_12*a.y);
    result.x -= vcn.z*(G1_13*a.x + G3_13*a.z);

    result.y = VDDX(vcn.x, a.y) + VDDY(vcn.y, a.y) + VDDZ(vcn.z, a.y);
    result.y -= vcn.x*(G1_12*a.x + G2_12*a.y);
    result.y -= vcn.y*(G1_22*a.x + G2_22*a.y + G3_22*a.z);
    result.y -= vcn.z*(G2_23*a.y + G3_23*a.z);

    result.z = VDDX(vcn.x, a.z) + VDDY(vcn.y, a.z) + VDDZ(vcn.z, a.z);
    result.z -= vcn.x*(G1_13*a.x + G3_13*a.z);
    result.z -= vcn.y*(G2_23*a.y + G3_23*a.z);
    result.z -= vcn.z*(G1_33*a.x + G2_33*a.y + G3_33*a.z);

    result.covariant = true;
  }else {
    
    result.x = VDDX(vcn.x, a.x) + VDDY(vcn.y, a.x) + VDDZ(vcn.z, a.x);
    result.x += vcn.x*(G1_11*a.x + G1_12*a.y + G1_13*a.z);
    result.x += vcn.y*(G1_12*a.x + G1_22*a.y);
    result.x += vcn.z*(G1_13*a.x + G1_33*a.z);
    
    result.y = VDDX(vcn.x, a.y) + VDDY(vcn.y, a.y) + VDDZ(vcn.z, a.y);
    result.y += vcn.x*(G2_11*a.x + G2_12*a.y);
    result.y += vcn.y*(G2_12*a.x + G2_22*a.y + G2_23*a.z);
    result.y += vcn.z*(G2_23*a.y + G2_33*a.z);
    
    result.z = VDDX(vcn.x, a.z) + VDDY(vcn.y, a.z) + VDDZ(vcn.z, a.z);
    result.z += vcn.x*(G3_11*a.x + G3_13*a.z);
    result.z += vcn.y*(G3_22*a.y + G3_23*a.z);
    result.z += vcn.z*(G3_13*a.x + G3_23*a.y + G3_33*a.z);

    result.covariant = false;
  }
  
#ifdef CHECK
  msg_stack.pop(msg_pos);
#endif

  return result;
}
Example #2
0
const Field3D V_dot_Grad(const Vector2D &v, const Field3D &f)
{
  Field3D result;
  
#ifdef CHECK
  int msg_pos = msg_stack.push("V_dot_Grad( Vector2D , Field3D )");
#endif

  // Get contravariant components of v
  Vector2D vcn = v;
  vcn.to_contravariant();

  result = VDDX(vcn.x, f) + VDDY(vcn.y, f) + VDDZ(vcn.z, f);

#ifdef CHECK
  msg_stack.pop(msg_pos);
#endif

  return result;
}
Example #3
0
const Field2D Div(const Vector2D &v, CELL_LOC outloc)
{
  Field2D result;

#ifdef CHECK
  int msg_pos = msg_stack.push("Div( Vector2D )");
#endif
  
  // get contravariant components of v
  Vector2D vcn = v;
  vcn.to_contravariant();
  
  result = DDX(J*vcn.x);
  result += DDY(J*vcn.y);
  result += DDZ(J*vcn.z);
  result /= J;

#ifdef CHECK
  msg_stack.pop(msg_pos);
#endif

  return result;
}
Example #4
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;
}