Beispiel #1
0
void PressureTable::BCAST_pressure(int mpi_root, MPI_Comm mpi_comm) {
  // Broadcast Table4D attributes
  BCAST(mpi_root, mpi_comm);

  // TableFileName, version, CombustionModel, ChemTableType are not used during the computation and are therefore not broadcast
  // TODO: Broadcast them anyway
  char buffer_m[kStrMed];
  int nVar = GetNumberVariables();
  size_t dum;
  for (int i=0; i<nVar; ++i) {
    if (mpi_rank == mpi_root) {
      for (int j=0; j<kStrMed-1; ++j) strcpy(&buffer_m[j]," ");
      VarNames[i].copy(&buffer_m[0], kStrMed);
      dum = VarNames[i].size();
      strcpy(&buffer_m[dum],"\0");
    }
    MPI_Bcast(buffer_m,kStrMed,MPI_CHAR,mpi_root,mpi_comm);    
    if (mpi_rank != mpi_root) AddVarName(buffer_m);
  }

}
Beispiel #2
0
void PressureTable::WriteTable(string output)
{
  FILE   *inFp = 0;
  char   filename[kStrLong], buffer_m[kStrMed];
  size_t dum;

  if (mpi_rank == 0) cout << endl << "***** Write table to file *****" << endl << endl;

  // ***************
  // Open table file
  // ***************
  if (output == "debug") cout << "Opening file "<< TableFilename << endl;
  TableFilename.copy(&filename[0], kStrLong);
  dum = TableFilename.size();
  if (dum < kStrLong) { strcpy(&filename[dum], "\0"); }
  else { cerr << "### Chemistry table file name is too long! ###" << endl; throw(-1); }

  if (!(inFp = fopen(filename, "wb"))) { cerr << "### Could not open chemistry table file " << filename << " ###" << endl; throw(-1); }

  // ************************
  // Write table general info
  // ************************

  // Version
  if (output == "debug") cout << "Write version " << version <<endl;
  dum = fwrite(&version, sizeof(double), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: version ###" << endl; throw(-1); }

  // CombustionModel
  if (output == "debug") cout << "Write model " << CombustionModel << endl;
  CombustionModel.copy(&buffer_m[0], kStrMed);
  dum = CombustionModel.size();
  if (dum < kStrMed) {strcpy(&buffer_m[dum], "\0");}
  else { cerr << "### Combustion model name is too long! ###" << endl; throw(-1); }

  dum = fwrite(&buffer_m[0], sizeof(char), kStrMed, inFp);
  if (dum != kStrMed) { cerr << "### Error writing file: Combustion model ###" << endl; throw(-1);}

  // ChemTableType
  if (output == "debug") cout << "Write ChemTableType " << ChemTableType << endl;
  ChemTableType.copy(&buffer_m[0], kStrMed);
  dum = ChemTableType.size();
  if (dum < kStrMed) { strcpy(&buffer_m[dum], "\0"); }
  else { cerr << "### Chem Table type is too long! ###" << endl; throw(-1); }

  dum = fwrite(&buffer_m[0], sizeof(char), kStrMed, inFp);
  if (dum != kStrMed) {cerr << "### Error writing file: Chem Table type ###" << endl; throw(-1);}

  // **********************
  // Write table dimensions
  // **********************
  int nPress = GetDimension1();
  if (output == "debug") cout << "Write nPress "<< nPress << endl;
  dum = fwrite(&nPress, sizeof(int), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: nPress ###" << endl; throw(-1); }

  int nZm = GetDimension2();
  if (output == "debug") cout << "Write nZm "<< nZm << endl;
  dum = fwrite(&nZm, sizeof(int), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: nZm ###" << endl; throw(-1); }

  int nZv = GetDimension3();
  if (output == "debug") cout << "Write nZv "<< nZv << endl;
  dum = fwrite(&nZv, sizeof(int), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: nZv ###" << endl; throw(-1); }

  int nC = GetDimension4();
  if (output == "debug") cout << "Write nC "<< nC << endl;
  dum = fwrite(&nC, sizeof(int), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: nC ###" << endl; throw(-1); }

  int nVar = GetNumberVariables();
  if (output == "debug") cout << "Write nVar "<< nVar << endl;
  dum = fwrite(&nVar, sizeof(int), 1, inFp);
  if (dum != 1) { cerr << "### Error writing file: nVar ###" << endl; throw(-1);}

  // ***********************
  // Write table coordinates 
  // ***********************
  if (output == "debug") cout << "Write Pressure vector "<< endl;
  double *Pressure = new double[nPress];
  CopyCoordinate1(Pressure);
  dum = fwrite(Pressure, sizeof(double), nPress, inFp);
  if (dum != nPress) { cerr << "### Error writing file: Pressure ###" << endl; throw(-1);}

  if (output == "debug") cout << "Write Zm vector "<< endl;
  double *Zm = new double[nZm];
  CopyCoordinate2(Zm);
  dum = fwrite(Zm, sizeof(double), nZm, inFp);
  if (dum != nZm) { cerr << "### Error writing file: Zm ###" << endl; throw(-1);}

  if (output == "debug") cout << "Write Zv vector "<< endl;
  double *Zv = new double[nZv];
  CopyCoordinate3(Zv);
  dum = fwrite(Zv, sizeof(double), nZv, inFp);
  if (dum != nZv) { cerr << "### Error writing file: Zv ###" << endl; throw(-1);}

  if (output == "debug") cout << "Write C vector "<< endl;
  double *CC = new double[nC]; 
  CopyCoordinate4(CC);
  dum = fwrite(CC, sizeof(double), nC, inFp);
  if (dum != nC) { cerr << "### Error writing file: CC ###" << endl; throw(-1);}

  // ***********************
  // Write name of variables
  // ***********************
  for (int l = 0; l < nVar; l++)
  {
    if (output == "debug") cout << "Write VarName "<< VarNames[l] << endl;
    VarNames[l].copy(&buffer_m[0], kStrMed);
    dum = VarNames[l].size();
    if (dum < kStrMed) {strcpy(&buffer_m[dum], "\0");}
    else { cerr << "### Variable name " << VarNames[l] << " is too long! ###" << endl; throw(-1);}

    dum = fwrite(&buffer_m, sizeof(char), kStrMed, inFp);
    if (dum != kStrMed) { cerr << "### Error writing file: Variable name " << VarNames[l] << " ###" << endl; throw(-1);}
  }

  // ****************
  // Write table data 
  // ****************
  if (output == "debug") cout << "Write Table" << endl;
  for (int ipress=0; ipress <nPress; ipress++)
    for (int i = 0; i < nZm; i++)
      for (int j = 0; j < nZv; j++)
        for (int k = 0; k < nC; k++)
          for (int n = 0; n < nVar; n++)
          {
            float value = GetTableValue(ipress,i,j,k,n);
            dum = fwrite(&value, sizeof(float), 1, inFp);
            if (dum != 1) { cerr << "### Error reading file: Table -> " << ipress << " " << i << " " << j << " " << k << " " << n << " ### " << endl; throw(-1);}
          }
  // ****************
  // Close table file
  // ****************
  if (output == "debug") cout << "Close file" << endl;
  fclose(inFp);
}
Beispiel #3
0
void PressureTable::print(void) {
	int nPress = GetDimension1();
	int nZm    = GetDimension2();
	int nZv    = GetDimension3();
	int nC     = GetDimension4();
	int nVar   = GetNumberVariables();

	cout << endl;
	cout << "------------------------------------------------------" << endl;
	cout << "  Multi-Pressure Chemtable: " << TableFilename << endl;
	cout << "------------------------------------------------------" << endl;
  cout << "  - Chemistry table type : " << ChemTableType << endl;
  cout << "  - Combustion model     : " << CombustionModel << endl;
  cout << "  - Chemistry table size : " << nVar   << " variables" << endl;
  cout << "                           " << nPress << " (Pressure) " << endl;
  cout << "                           " << nZm    << " (Mean Mixture Fraction) "<< endl;
  cout << "                           " << nZv    << " (Mixture Fraction Variance) " << endl;
  cout << "                           " << nC     << " (Progress Variable) " << endl;
  cout << endl;

  cout << "  - Input coordinates    : " << endl;
  //cout << setiosflags(ios::fixed);
  cout << setprecision(4);
  //cout << dec;
  // Pressure vec
	double *vec = new double[nPress];
	CopyCoordinate1(vec);
	cout  <<"    x1 : Pressure   =" << "\t ["; cout.width(6); cout << vec[0] << " ... "; cout.width(6); cout << vec[nPress-1] << "]" << endl;
	delete [] vec;
	// Mixture Fraction Vec
	vec = new double[nZm];
	CopyCoordinate2(vec);
	cout  << "    x2 : Zmean      =" << "\t ["; cout.width(6); cout << vec[0] << " ... "; cout.width(6); cout << vec[nZm-1] << "]" << endl;
	delete [] vec;
	// Mixture Fraction Variance vec
	vec = new double[nZv];
	CopyCoordinate3(vec);
	cout  << "    x3 : Zvar       =" << "\t ["; cout.width(6); cout << vec[0] << " ... "; cout.width(6); cout << vec[nZv-1] << "]" << endl;
	delete [] vec;
	// Progress Variable vec
	vec = new double[nC];
	CopyCoordinate4(vec);
  cout  << "    x4 : Prog       =" << "\t ["; cout.width(6); cout << vec[0] << " ... "; cout.width(6); cout << vec[nC-1] << "]" << endl;
  delete [] vec;
  cout << endl;

  // Display variables names, min and max
  cout << "  - Stored variables     : " << endl;
	float minval, maxval;
	int mi1, mi2, mi3, ma1, ma2, ma3, mi4, ma4;
	for (int l = 0; l < nVar; l++)
	{
		GetArrayInfo(l, minval, maxval, mi1, mi2, mi3, mi4, ma1, ma2, ma3, ma4);
		cout.width(6);
		cout << l << ". ";
		cout.width(12);
		cout << VarNames[l] << "  =  ["; cout.width(12); cout << minval << " ... "; cout.width(12); cout << maxval << "]" << endl;
	}
	cout << "------------------------------------------------------" << endl;
	cout << endl;
}
Beispiel #4
0
wxString wxPlotFunction::GetVariableName(size_t n) const
{
    wxCHECK_MSG(Ok(), wxEmptyString, wxT("invalid plotfunction"));
    wxCHECK_MSG((int(n) < GetNumberVariables()), wxEmptyString, wxT("invalid variable index"));
    return M_PLOTFUNCDATA->m_parser.GetVariableName(n);
}