⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dofdata.c

📁 cfd求解器使用与gmsh网格的求解
💻 C
📖 第 1 页 / 共 4 页
字号:
  Dof_CloseFile(DOF_RES) ;  LinAlg_SequentialEnd();  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ W r i t e F i l e R E S _ E x t e n d M H                       *//* ------------------------------------------------------------------------ */void  Dof_WriteFileRES_ExtendMH(char * Name_File, struct DofData * DofData_P, int Format,				int NbrH) {  gVector x;  double d;  int i, inew;  GetDP_Begin("Dof_WriteFileRES_ExtendMH");  LinAlg_SequentialBegin() ;  Dof_OpenFile(DOF_RES, Name_File, (char*)(Format ? "ab" : "a")) ;  if(Current.RankCpu == 0){    fprintf(File_RES, "$Solution  /* DofData #%d */\n", DofData_P->Num) ;    fprintf(File_RES, "%d 0 0 0 \n", DofData_P->Num) ;  }  LinAlg_CreateVector(&x, &DofData_P->Solver, (DofData_P->NbrDof / Current.NbrHar) * NbrH,		      DofData_P->NbrPart, DofData_P->Part) ;  LinAlg_ZeroVector(&x) ;  for (i=0 ; i<DofData_P->NbrDof ; i++){    LinAlg_GetDoubleInVector(&d, &DofData_P->CurrentSolution->x, i);    inew = (i / Current.NbrHar) * NbrH + i % Current.NbrHar;    LinAlg_SetDoubleInVector(d, &x, inew);  }  Format ?     LinAlg_WriteVector(File_RES,&x) :    LinAlg_PrintVector(File_RES,&x) ;  if(Current.RankCpu == Current.NbrCpu-1)    fprintf(File_RES, "$EndSolution\n") ;  Dof_CloseFile(DOF_RES) ;  LinAlg_DestroyVector(&x) ;  LinAlg_SequentialEnd() ;    GetDP_End ;}void  Dof_WriteFileRES_MHtoTime(char * Name_File, struct DofData * DofData_P, 				int Format, List_T * Time_L) {  gVector x;  double Time, d1, d2, d, *Pulsation;  int iT, i, j, k;  GetDP_Begin("Dof_WriteFileRES_MHtoTime");  LinAlg_SequentialBegin() ;  Dof_OpenFile(DOF_RES, Name_File, (char*)(Format ? "ab" : "a")) ;  for(iT=0 ; iT<List_Nbr(Time_L) ; iT++){    List_Read(Time_L, iT, &Time);    if(Current.RankCpu == 0){      fprintf(File_RES, "$Solution  /* DofData #%d */\n", DofData_P->Num) ;      fprintf(File_RES, "%d %e 0 %d \n", DofData_P->Num,Time,iT) ;    }    Pulsation = DofData_P->Val_Pulsation ;         LinAlg_CreateVector(&x, &DofData_P->Solver, DofData_P->NbrDof/Current.NbrHar,			DofData_P->NbrPart, DofData_P->Part) ;        LinAlg_ZeroVector(&x) ;        for (i=0 ; i<DofData_P->NbrDof/Current.NbrHar ; i++) {      d = 0;      for (k=0 ; k<Current.NbrHar/2 ; k++) {	j = i * Current.NbrHar + 2*k ; 	LinAlg_GetDoubleInVector(&d1, &DofData_P->CurrentSolution->x, j) ;	LinAlg_GetDoubleInVector(&d2, &DofData_P->CurrentSolution->x, j+1) ;	d += d1 * cos(Pulsation[k]*Time) - d2 * sin(Pulsation[k]*Time) ;       }      LinAlg_SetDoubleInVector(d, &x, i) ;    }        Format ?       LinAlg_WriteVector(File_RES,&x) :      LinAlg_PrintVector(File_RES,&x) ;        if(Current.RankCpu == Current.NbrCpu-1)      fprintf(File_RES, "$EndSolution\n") ;  }  Dof_CloseFile(DOF_RES) ;  LinAlg_DestroyVector(&x) ;  LinAlg_SequentialEnd() ;    GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ W r i t e F i l e R E S                                         *//* ------------------------------------------------------------------------ */void  Dof_WriteFileRES(char * Name_File, struct DofData * DofData_P, int Format,		       double Val_Time, double Val_TimeImag, int Val_TimeStep) {  GetDP_Begin("Dof_WriteFileRES");  LinAlg_SequentialBegin() ;  Dof_OpenFile(DOF_RES, Name_File, (char*)(Format ? "ab" : "a")) ;  if(Current.RankCpu == 0){    fprintf(File_RES, "$Solution  /* DofData #%d */\n", DofData_P->Num) ;    fprintf(File_RES, "%d %.16g %.16g %d\n", DofData_P->Num, Val_Time, 	    Val_TimeImag, Val_TimeStep) ;  }  Format ?     LinAlg_WriteVector(File_RES, &DofData_P->CurrentSolution->x) :    LinAlg_PrintVector(File_RES, &DofData_P->CurrentSolution->x) ;  if(Current.RankCpu == Current.NbrCpu-1)    fprintf(File_RES, "$EndSolution\n") ;  Dof_CloseFile(DOF_RES) ;  LinAlg_SequentialEnd() ;    GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ R e a d F i l e R E S                                           *//* ------------------------------------------------------------------------ */void  Dof_ReadFileRES(List_T * DofData_L, struct DofData * Read_DofData_P,		      int Read_DofData, double *Time, double *TimeImag,		      double *TimeStep) {  int             Num_DofData, Val_TimeStep, Format = 0, Read ;  double          Val_Time, Val_TimeImag = 0., Version = 0.;  struct DofData  * DofData_P = NULL ;  struct Solution Solution_S ;  char            String[MAX_STRING_LENGTH] ;  GetDP_Begin("Dof_ReadFileRES");  while (1) {    do {       fgets(String, MAX_STRING_LENGTH, File_RES) ;       if (feof(File_RES))  break ;    } while (String[0] != '$') ;      if (feof(File_RES))  break ;    /*  F o r m a t  */    if (!strncmp(&String[1], "ResFormat", 9)) {      fscanf(File_RES, "%lf %d\n", &Version, &Format) ;    }    /*  S o l u t i o n  */    if (!strncmp(&String[1], "Solution", 8)) {      /* don't use fscanf directly on the stream here: the data that	 follows can be binary, and the first character could be	 e.g. 0x0d, which would cause fscanf to eat-up one character	 too much, leading to an offset in fread */      fgets(String, MAX_STRING_LENGTH, File_RES) ;       if(Version <= 1.0)	sscanf(String, "%d %lf %d", &Num_DofData, &Val_Time, &Val_TimeStep) ;      else	sscanf(String, "%d %lf %lf %d", &Num_DofData, &Val_Time, &Val_TimeImag, 	       &Val_TimeStep) ;      if (Read_DofData < 0){	Read = 1 ; DofData_P = (struct DofData*)List_Pointer(DofData_L, Num_DofData) ;      }      else if (Num_DofData == Read_DofData) {	Read = 1 ; DofData_P = Read_DofData_P ;       }      else {	Read = 0 ;      }      if(Read){	Solution_S.Time = Val_Time ;	Solution_S.TimeImag = Val_TimeImag ;	Solution_S.TimeStep = Val_TimeStep ;	Solution_S.SolutionExist = 1 ;	Solution_S.TimeFunctionValues = NULL ;	LinAlg_CreateVector(&Solution_S.x, &DofData_P->Solver, DofData_P->NbrDof,			    DofData_P->NbrPart, DofData_P->Part) ;	Format ? 	  LinAlg_ReadVector(File_RES, &Solution_S.x) :	  LinAlg_ScanVector(File_RES, &Solution_S.x) ;	if (DofData_P->Solutions == NULL)	  DofData_P->Solutions = List_Create( 20, 20, sizeof(struct Solution)) ;	List_Add(DofData_P->Solutions, &Solution_S) ;      }    }    do {      fgets(String, MAX_STRING_LENGTH, File_RES) ;      if (feof(File_RES)) 	Msg(WARNING, "Prematured end of file (Time Step %d)", Val_TimeStep);    } while (String[0] != '$') ;  }   /* while 1 ... */  *Time = Val_Time ;  *TimeImag = Val_TimeImag ;  *TimeStep = (double)Val_TimeStep ;  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ T r a n s f e r D o f T r e e T o L i s t                       *//* ------------------------------------------------------------------------ */void  Dof_TransferDofTreeToList(struct DofData * DofData_P) {  GetDP_Begin("Dof_TransferDofTreeToList");  if (DofData_P->DofTree) {    DofData_P->DofList = Tree2List(DofData_P->DofTree) ;    Tree_Delete(DofData_P->DofTree) ;    DofData_P->DofTree = NULL ;    DofData_P->NbrAnyDof = List_Nbr(DofData_P->DofList) ;  }  Dof_InitDofType(DofData_P) ;  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ I n i t D o f T y p e                                           *//* ------------------------------------------------------------------------ */void  Dof_InitDofType(struct DofData * DofData_P) {  struct Dof  * Dof_P, * Dof_P0 ;  int  i ;  GetDP_Begin("Dof_InitDofType");  if (!DofData_P->NbrAnyDof){    GetDP_End;  }  Dof_P0 = (struct Dof *)List_Pointer(DofData_P->DofList, 0) ;  for (i = 0 ; i < DofData_P->NbrAnyDof ; i++) {    Dof_P = Dof_P0 + i ;    switch (Dof_P->Type) {    case DOF_LINK :    case DOF_LINKCPLX :      Dof_P->Case.Link.Dof =	Dof_GetDofStruct(DofData_P, Dof_P->NumType,			 Dof_P->Case.Link.EntityRef, Dof_P->Harmonic) ;      if (Dof_P->Case.Link.Dof == NULL) {	Dof_P->Case.Link.Dof = /* Attention: bricolage ... */	  Dof_GetDofStruct(DofData_P, Dof_P->NumType-1,			   Dof_P->Case.Link.EntityRef, Dof_P->Harmonic) ;	if (Dof_P->Case.Link.Dof == NULL)	  Msg(GERROR,"Wrong Link Constraint: reference Dof (%d %d %d) does not exist",	      Dof_P->NumType, Dof_P->Case.Link.EntityRef, Dof_P->Harmonic);      }      /*      if (Dof_P->Case.Link.Dof == NULL)	Msg(GERROR,"Wrong Link Constraint: reference Dof (%d %d %d) does not exist",	    Dof_P->NumType, Dof_P->Case.Link.EntityRef, Dof_P->Harmonic);      */      break ;    default :      break ;    }  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  P R E P R O C E S S I N G   ( C o d e s   i n   T r e e )               *//* ------------------------------------------------------------------------ *//* ------------------------------------------------------------------------ *//*  D o f _ A d d F u n c t i o n S p a c e I n d e x                       *//* ------------------------------------------------------------------------ */void  Dof_AddFunctionSpaceIndex(int Index_FunctionSpace) {  GetDP_Begin("Dof_AddFunctionSpaceIndex");  if (CurrentDofData->FunctionSpaceIndex == NULL)    CurrentDofData->FunctionSpaceIndex = List_Create(10, 5, sizeof(int)) ;  if (List_PQuery      (CurrentDofData->FunctionSpaceIndex, &Index_FunctionSpace, fcmp_int) == NULL) {    List_Add(CurrentDofData->FunctionSpaceIndex, &Index_FunctionSpace) ;    List_Sort(CurrentDofData->FunctionSpaceIndex, fcmp_int) ;  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ A d d T i m e F u n c t i o n I n d e x                         *//* ------------------------------------------------------------------------ */void  Dof_AddTimeFunctionIndex(int Index_TimeFunction) {  GetDP_Begin("Dof_AddTimeFunctioIndex");  if (List_PQuery      (CurrentDofData->TimeFunctionIndex, &Index_TimeFunction, fcmp_int) == NULL) {    List_Add(CurrentDofData->TimeFunctionIndex, &Index_TimeFunction) ;    List_Sort(CurrentDofData->TimeFunctionIndex, fcmp_int) ;  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ A d d P u l s a t i o n                                         *//* ------------------------------------------------------------------------ */void  Dof_AddPulsation(struct DofData * DofData_P, double Val_Pulsation) {  GetDP_Begin("Dof_AddPulsation");  if (DofData_P->Pulsation == NULL)    DofData_P->Pulsation = List_Create(1, 2, sizeof(double)) ;  if (List_PQuery      (DofData_P->Pulsation, &Val_Pulsation, fcmp_double) == NULL) {    List_Add(DofData_P->Pulsation, &Val_Pulsation) ;    List_Sort(DofData_P->Pulsation, fcmp_double) ;  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ D e f i n e A s s i g n F i x e d D o f                         *//* ------------------------------------------------------------------------ */void  Dof_DefineAssignFixedDof(int D1, int D2, int NbrHar, double *Val, 			       int Index_TimeFunction) {  struct Dof  Dof, * Dof_P ;  int         k ;  GetDP_Begin("Dof_DefineAssignedFixedDof");  Dof.NumType = D1 ;  Dof.Entity = D2 ;      for(k=0 ; k<NbrHar ; k+=gSCALAR_SIZE){    Dof.Harmonic = k ;    if (!(Dof_P = (struct Dof *)Tree_PQuery(CurrentDofData->DofTree, &Dof))) {      Dof.Type = DOF_FIXED ;      LinAlg_SetScalar(&Dof.Val, &Val[k]) ;      Dof.Case.FixedAssociate.TimeFunctionIndex = Index_TimeFunction + 1 ;      Dof_AddTimeFunctionIndex(Index_TimeFunction + 1) ;      Tree_Add(CurrentDofData->DofTree, &Dof) ;    }    else if(Dof_P->Type == DOF_UNKNOWN) {      if(Flag_VERBOSE == 10)	Msg(INFO, "Overriding unknown Dof with fixed Dof");      Dof_P->Type = DOF_FIXED ;      LinAlg_SetScalar(&Dof_P->Val, &Val[k]) ;      Dof_P->Case.FixedAssociate.TimeFunctionIndex = Index_TimeFunction + 1 ;      Dof_AddTimeFunctionIndex(Index_TimeFunction + 1) ;    }  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ D e f i n e A s s i g n S o l v e D o f                         *//* ------------------------------------------------------------------------ */void  Dof_DefineAssignSolveDof(int D1, int D2, int NbrHar, int Index_TimeFunction) {  struct Dof  Dof ;  int         k ;    GetDP_Begin("Dof_DefineAssignSolveDof");  Dof.NumType = D1 ;  Dof.Entity = D2 ;    for(k=0 ; k<NbrHar ; k+=gSCALAR_SIZE){    Dof.Harmonic = k ;    if (!Tree_PQuery(CurrentDofData->DofTree, &Dof)) {      Dof.Type = DOF_FIXED_SOLVE ;      Dof.Case.FixedAssociate.TimeFunctionIndex = Index_TimeFunction + 1 ;      Dof_AddTimeFunctionIndex(Index_TimeFunction + 1) ;       Tree_Add(CurrentDofData->DofTree, &Dof) ;    }  }  GetDP_End ;}/* ------------------------------------------------------------------------ *//*  D o f _ D e f i n e I n i t F i x e d D o f                             *//* ------------------------------------------------------------------------ */void  Dof_DefineInitFixedDof(int D1, int D2, int NbrHar, double *Val) {  struct Dof  Dof ;  int         k ;  GetDP_Begin("Dof_DefineInitFixesDof");  Dof.NumType = D1 ;  Dof.Entity = D2 ;  for(k=0 ; k<NbrHar ; k+=gSCALAR_SIZE){    Dof.Harmonic = k ;    if (!Tree_PQuery(CurrentDofData->DofTree, &Dof)) {      Dof.Type = DOF_UNKNOWN_INIT ;      LinAlg_SetScalar(&Dof.Val, &Val[k]) ;      Dof.Case.Unknown.NumDof = ++(CurrentDofData->NbrDof) ;      Tree_Add(CurrentDofData->DofTree, &Dof) ;    }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -