コード例 #1
0
ファイル: writesolver.c プロジェクト: Dylnn/Civil-CFD
int write_solver(struct solver_data *solver, char *filename) {
  FILE *fp;
  
  if(filename == NULL || solver == NULL) {
    printf("error: passed null arguments to write_solver\n");
    return(1);
  }

  fp = fopen(filename, "w");

  if(fp == NULL) {
    printf("error: cannot open %s in write_solver\n",filename);
    return(1);
  }

	if(solver->pressure == vof_pressure_gmres) fprintf(fp,"gmres 1\n");
	else if(solver->pressure == vof_pressure_gmres_mpi) fprintf(fp,"gmres_mpi 1\n");
	else if(solver->pressure == vof_pressure) fprintf(fp,"sor 1\n");

  fprintf(fp,"gravity %e %e %e\n",solver->gx, solver->gy, solver->gz);
  fprintf(fp,"nu %e\n",solver->nu);
  fprintf(fp,"rho %e\n",solver->rho);
  fprintf(fp,"t %e\n",solver->t);
  fprintf(fp,"delt %e\n",solver->delt);
  fprintf(fp,"writet %e\n",solver->writet);
  fprintf(fp,"endt %e\n",solver->endt);
  if(solver->deltcal == NULL) fprintf(fp,"autot 0\n");
  
  if(kE_check(solver)) fprintf(fp,"turbulence 1\n");
  else fprintf(fp,"turbulence 0\n");

  fclose(fp);

  return 0;
}
コード例 #2
0
ファイル: writesolver.c プロジェクト: Dylnn/Civil-CFD
int write_initial(struct solver_data *solver, char *filename) {
  FILE *fp;
  double velocity[3], inside[3];
  double value;
  
  if(filename == NULL || solver == NULL) {
    printf("error: passed null arguments to write_initial\n");
    return(1);
  }

  fp = fopen(filename, "w");

  if(fp == NULL) {
    printf("error: cannot open %s in write_initial\n",filename);
    return(1);
  }

  solver_get_initial_vector(solver, "velocity", velocity);
  fprintf(fp,"velocity %e %e %e\n",velocity[0],velocity[1],velocity[2]);
  
  value = solver_get_initial_scalar(solver, "vof_height");  
  if(value>0) fprintf(fp,"vof_height %e\n",value);
  
  value = solver_get_initial_scalar(solver, "hydrostatic");    
  if(value > 0) fprintf(fp,"hydrostatic 1\n");

  while(solver_get_initial_vector(solver, "inside", inside) != 1); // make sure we start at the first instance
  while(solver_get_initial_vector(solver, "inside", inside) != 1) {
    fprintf(fp,"inside %e %e %e\n",inside[0],inside[1],inside[2]);
  }
  
  value = solver_get_initial_scalar(solver, "kE_k");     
  if(value > 0 && kE_check(solver)) fprintf(fp,"kE_k %e\n",value);

  fclose(fp);

  return 0;
}
コード例 #3
0
ファイル: solver.c プロジェクト: civilcfd/Civil-CFD
int solver_set_initial(struct solver_data *solver, char *param, int dims, 
                   double *vector) {
  long int z_height;

  if(solver == NULL || param == NULL || vector == NULL) {
    printf("error: null values passed to solver_set_initial\n");
    return(1);
  }

  if(strcmp(param, "inside")==0) {
    if(dims < 3) {
      printf("error in source file: inside requires 3 arguments\n");
      return(1);
    }  
  
    mesh_fill_vof(solver->mesh, vector);
  
  } else if(strcmp(param, "velocity")==0) {
    if(dims < 3) {
      printf("error in source file: velocity requires 3 arguments\n");
      return(1);
    }
 
    mesh_set_array(solver->mesh, "u", vector[0], -1, 0, 0, 0, 0, 0);   
    mesh_set_array(solver->mesh, "v", vector[1], -1, 0, 0, 0, 0, 0);
    mesh_set_array(solver->mesh, "w", vector[2], -1, 0, 0, 0, 0, 0);          
  
  } else if(strcmp(param, "u")==0) {
    if(dims != 1) {
      printf("error in source file: u requires 1 argument\n");
      return(1);
    }

    mesh_set_array(solver->mesh, "u", vector[0], -1, 0, 0, 0, 0, 0);
  } else if(strcmp(param, "v")==0) {
    if(dims != 1) {
      printf("error in source file: v requires 1 argument\n");
      return(1);
    }

    mesh_set_array(solver->mesh, "v", vector[0], -1, 0, 0, 0, 0, 0);  
  } else if(strcmp(param, "w")==0) {
    if(dims != 1) {
      printf("error in source file: w requires 1 argument\n");
      return(1);
    }

    mesh_set_array(solver->mesh, "w", vector[0], -1, 0, 0, 0, 0, 0);  
  } else if(strcmp(param, "vof_height")==0) {
    if(dims < 1) {
      printf("error in source file: vof_height requires 1 argument\n");
      return(1);
    }
    
    solver->vof_height = vector[0];
    solver->vof_delay = vector[1];
    
    if(fmod(solver->vof_height,solver->mesh->delz) < solver->emf) solver->vof_height -= solver->min_vof * 100;
    
    if(solver->vof_delay < solver->emf) {
    
      z_height = floor(solver->vof_height / solver->mesh->delz);

      mesh_set_array(solver->mesh, "vof", 1.0, 0, solver->mesh->imax, 
                                               0, solver->mesh->jmax, 
                                               0, z_height);  
                                               
      if(solver->vof_height / solver->mesh->delz - z_height > 0) {
        mesh_set_array(solver->mesh, "vof", solver->vof_height / solver->mesh->delz - z_height, 
                                               0, solver->mesh->imax, 
                                               0, solver->mesh->jmax, 
                                               z_height, z_height+1);        
      }
    
    }
                                             
  } else if(strcmp(param, "hydrostatic")==0) {
    if(dims < 1) {
      printf("error in source file: hydrostatic requires 1 argument\n");
      return(1);
    }
    
    if(vector[0]>0) mesh_set_hydrostatic(solver->mesh, fabs(solver->gz), solver->rho);  
    
  } else if(strcmp(param, "kE_k")==0) {
    if(dims < 1) {
      printf("error in source file: kE_k requires 1 argument\n");
      return(1);
    }
    if(!kE_check(solver)) {
      printf("error in source file: kE_k called but turbulence model is not k-Epsilon\n");
      return(1);
    }
    
    kE_set_internal(solver, vector[0], 0);
  }

  return 0;
}