Example #1
0
 string getHint(string secret, string guess) {
     int i, j, bulls, cows;
     string str;
     
     bulls = 0;
     cows = 0;
     str = "";
     
     for (i = 0; i < secret.size(); i++) {
         if (secret[i] == guess[i]) {
             secret[i] = 'x';
             guess[i] = 'y';
             bulls++;
         }
     }
     
     for (i = 0; i < secret.size(); i++) {
         for (j = 0; j < guess.size(); j++) {
             if (guess[j] == secret[i]) {
                 secret[i] = 'x';
                 guess[j] = 'y';
                 cows++;
                 break;
             }
         }
     }
     
     str += number2string(bulls);
     str += 'A';
     str += number2string(cows);
     str += 'B';
     
     return str;
 }
void
MultiscaleAlgorithmNewton::subIterate()
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream ( 8013 ) << "MultiscaleAlgorithmNewton::subIterate() \n";
#endif

    multiscaleAlgorithm_Type::subIterate();

    // Verify tolerance
    if ( checkResidual ( 0 ) )
    {
        return;
    }

    M_multiscale->exportCouplingVariables ( *M_couplingVariables );

    multiscaleVectorPtr_Type delta ( new multiscaleVector_Type ( *M_couplingResiduals, Unique ) );
    *delta = 0.0;

    for ( UInt subIT (1); subIT <= M_subiterationsMaximumNumber; ++subIT )
    {
        // Compute the Jacobian
        assembleJacobianMatrix();

        // Set matrix and RHS
        M_solver.setOperator ( M_jacobian );
        M_solver.setRightHandSide ( M_couplingResiduals );

        // Solve Newton (without changing the sign of the residual)
        M_solver.solve ( delta );

        // Changing the sign of the solution
        *delta *= -1;

        // Update Coupling Variables using the Newton Method
        *M_couplingVariables += *delta;

        // Import Coupling Variables inside the coupling blocks
        M_multiscale->importCouplingVariables ( *M_couplingVariables );

        // Verify tolerance
        if ( checkResidual ( subIT ) )
        {
            return;
        }
    }

    save ( M_subiterationsMaximumNumber, M_couplingResiduals->norm2() );

    multiscaleErrorCheck ( Tolerance, "Newton algorithm residual: " + number2string ( M_couplingResiduals->norm2() ) +
                           " (required: " + number2string ( M_tolerance ) + ")\n", M_multiscale->communicator() == 0 );
}
Example #3
0
void
MultiscaleCoupling::saveSolution()
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream ( 8200 ) << "MultiscaleCoupling::saveSolution() \n";
#endif

    if ( myModelsNumber() > 0 )
    {
        for ( UInt i ( 0 ); i < modelsNumber(); ++i )
            if ( myModel ( i ) )
            {
                Real flowRate   ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryFlowRate ( M_boundaryIDs[i] ) );
                Real stress     ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryMeanNormalStress ( M_boundaryIDs[i] ) );
                Real totalStress ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryMeanTotalNormalStress ( M_boundaryIDs[i] ) );
                Real area       ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryArea ( M_boundaryIDs[i] ) );

                if ( isModelLeaderProcess ( i ) )
                {
                    std::ofstream output;
                    output << std::scientific << std::setprecision ( 15 );

                    std::string filename = multiscaleProblemFolder + multiscaleProblemPrefix + "_Coupling_" + number2string ( M_ID )
                                           + "_Flag_" + number2string ( i )
                                           + "_" + number2string ( multiscaleProblemStep ) + ".mfile";

                    if ( M_globalData->dataTime()->timeStepNumber() == 0 || ( multiscaleProblemStep > 0 &&
                            M_globalData->dataTime()->round ( M_globalData->dataTime()->time() - ( multiscaleSaveEachNTimeSteps - 1 ) * M_globalData->dataTime()->timeStep() ) == M_globalData->dataTime()->round ( M_globalData->dataTime()->initialTime() ) ) )
                    {
                        output.open ( filename.c_str(), std::ios::trunc );
                        output << "% Coupling Type: " << enum2String ( M_type, multiscaleCouplingsMap ) << std::endl;
                        output << "% Coupling Name: " << M_couplingName << std::endl;
                        output << "% Model:         " << number2string ( M_models[i]->ID() ) << std::endl;
                        output << "% Boundary Flag: " << number2string ( M_models[i]->boundaryFlag ( M_boundaryIDs[i] ) ) << std::endl << std::endl;
                        output << "% TIME                     FLOW RATE                STRESS                   TOTAL STRESS             AREA" << std::endl;
                    }
                    else
                    {
                        output.open ( filename.c_str(), std::ios::app );
                    }
                    output << "  " << M_globalData->dataTime()->time() << "    " << flowRate << "    " << stress << "    " << totalStress << "    " << area << std::endl;
                    output.close();
                }
            }
    }
}
Example #4
0
char *format_double(unsigned char *rec,int offset,int format_code) {	
	union { unsigned char cc[8];
		double d;} dconv;
	unsigned char *d,*s; 
	int i;
# ifdef WORDS_BIGENDIAN     
	for(s=rec+offset+8,d=dconv.cc,i=0;
			i<8;i++) *(d++)=*(--s);
# else       
	for(s=rec+offset,d=dconv.cc,i=0;
			i<8;i++) *(d++)=*(s++);
# endif     
	return number2string(dconv.d,format_code);					
}
Example #5
0
void read_article(player *p,char *str)
{
    char *oldstack;
    note *article;
    oldstack=stack;

    if (!*str) {
	tell_player(p,"Format: read <article-number>\n");
	return;
    }

    article=find_news_article(atoi(str));
    if (!article) {
	sprintf(stack,"No such news article '%s'\n",str);
	stack=end_string(stack);
	tell_player(p,oldstack);
	stack=oldstack;
	return;
    }
    article->read_count++;
    if (article->flags&ANONYMOUS) {
	if (p->residency&(LOWER_ADMIN|ADMIN))
	    sprintf(stack,"Subject: %s\nPosted annonymously on %s by %s.\n",
		    article->header,convert_time(article->date),article->name);
	else sprintf(stack,"Subject: %s\nPosted annonymously on %s.\n",
		     article->header,convert_time(article->date));
    }
    else sprintf(stack,"Subject: %s\nPosted by %s on %s.\n",article->header,
		 article->name,convert_time(article->date));
    stack=strchr(stack,0);
    if (article->read_count==1) strcpy(stack,"Article read once only.\n\n");
    else sprintf(stack,"Article has been read %s times.\n\n",
		 number2string(article->read_count));
    stack=strchr(stack,0);
    get_string(stack,article->text.where);
    stack=end_string(stack);
    pager(p,oldstack,0);
    stack=oldstack;
}
Example #6
0
void list_news(player *p,char *str)
{
    char *oldstack,middle[80];
    int page,pages,count,article,ncount=1;
    note *scan;
    oldstack=stack;
    
    if (!news_count) {
	tell_player(p,"No news articles to view.\n");
	return;
    }
    
    page=atoi(str);
    if (page<=0) page=1;
    page--;
    
    pages=(news_count-1)/(TERM_LINES-2);
    if (page>pages) page=pages;
    
    if (news_count==1) strcpy(middle,"There is one news article");
    else sprintf(middle,"There are %s articles",
		 number2string(news_count));
    pstack_mid(middle);

    count=page*(TERM_LINES-2);

    for(article=news_start;count;count--,ncount++) {
	scan=find_note(article);
	if (!scan) {
	    tell_player(p,"Bad news listing, aborted.\n");
	    log("error","Bad news list");
	    stack=oldstack;
	    return;
	}
	article=scan->next_sent;
    }
    for(count=0;(count<(TERM_LINES-1));count++,ncount++) {
	scan=find_note(article);
	if (!scan) break;
	if (p->residency&(LOWER_ADMIN|ADMIN))
	    sprintf(stack,"(%d) [%d] ",scan->id,ncount);
	else sprintf(stack,"[%d] ",ncount);
	while(*stack) *stack++;
	if (ncount<10) *stack++=' ';
	strcpy(stack,scan->header);
	while(*stack) *stack++;
	if (scan->flags&ANONYMOUS) {
	    if (p->residency&(LOWER_ADMIN|ADMIN)) sprintf(stack," <%s>\n",scan->name);
	    else strcpy(stack,"\n");
	}
	else sprintf(stack," (%s)\n",scan->name);
	stack=strchr(stack,0);
	article=scan->next_sent;
    }  

    sprintf(middle,"Page %d of %d",page+1,pages+1);
    pstack_mid(middle);

    *stack++=0;
    tell_player(p,oldstack);

    stack=oldstack;
}
Example #7
0
void view_received(player *p,char *str)
{
    char *oldstack,middle[80],*page_input;
    int page,pages,*scan,*scan_count,mcount=0,ncount=1,n;
    note *mail;
    saved_player *sp;
    oldstack=stack;
    
    if (*str && !isdigit(*str) && p->residency&(LOWER_ADMIN|ADMIN)) {
	page_input=next_space(str);
	if (*page_input) *page_input++=0;
	sp=find_saved_player(str);
	if (!sp) {
	    tell_player(p,"No such player in save files.\n");
	    return;
	}
	else scan=sp->mail_received;
	str=page_input;
    }
    else {
	if (!p->saved) {
	    tell_player(p,"You have no save file, and therefore no mail either.\n");
	    return;
	}
	sp=p->saved;
	scan=sp->mail_received;
    }

    if (!scan) {
	tell_player(p,"You have received no mail.\n");
	return;
    }

    p->saved_flags &= ~NEW_MAIL;

    for(scan_count=scan;*scan_count;scan_count++) mcount++;

    page=atoi(str);
    if (page<=0) page=1;
    page--;

    pages=(mcount-1)/(TERM_LINES-2);
    if (page>pages) page=pages;

    if (mcount==1) strcpy(middle,"You have received one letter");
    else sprintf(middle,"You have received %s letters",
		 number2string(mcount));
    pstack_mid(middle);

    ncount=page*(TERM_LINES-2);

    scan += ncount;

    for(n=0,ncount++;n<(TERM_LINES-1);n++,ncount++,scan++) {
	if (!*scan) break;
	mail=find_note(*scan);
	if (!mail) {
	    stack=oldstack;
	    tell_player(p,"Found mail that owner had deleted ...\n");
	    reconfigure_received_list(sp);
	    if (sp!=p->saved) {
		tell_player(p,"Reconfigured ... try again\n");
		return;
	    }
	    view_received(p,str);
	    return;
	}
	if (p->residency&(LOWER_ADMIN|ADMIN)) sprintf(stack,"(%d) [%d] ",mail->id,ncount);
	else sprintf(stack,"[%d] ",ncount);
	while(*stack) *stack++;
	if (ncount<10) *stack++=' ';
	strcpy(stack,mail->header);
	while(*stack) *stack++;
	if (mail->flags&ANONYMOUS) {
	    if (p->residency&(LOWER_ADMIN|ADMIN)) sprintf(stack," <%s>\n",mail->name);
	    else strcpy(stack,"\n");
	}
	else sprintf(stack," (%s)\n",mail->name);
	while(*stack) *stack++;
    }  

    sprintf(middle,"Page %d of %d",page+1,pages+1);
    pstack_mid(middle);

    *stack++=0;
    tell_player(p,oldstack);

    stack=oldstack;
}
int reduc_position( int cup, int bot, int eod, int fileno, int recno, int inout)
{
	int		tapetype_off = 3;
	int		stor1_off    = 2;
	int		stor2_off    = 12;
	int		filerec_off  = 13;
	int		*typep;
	int		*stor1p;
	int		*stor2p;
	int		*filerecp;
	int		current_file;
	int		current_rec;
	int		files2skip;
	int		recs2skip;
	int		blockfac;
	int		type;
	long int	bytepos;
	char		s1[4];
	char		in_file[128];         /* file names */
	char		out_file[128];        /* file names */
	int		n, created;

	struct	mtop 	mt_command;
	struct	mtget mt_status;
	char	msg1[1024] = "Position is - File/Record : ";
	char	msg2[1024] = "Positioning Exabyte to beginning of tape ...";
	char	msg3[1024] = "Positioning Exabyte to end of recorded data ...";
	char	msg4[1024] = "Positioning Exabyte to file : ";
	char	err0d[1024] = "Use the position at file/record no... ";
	char	msg2d[1024] = "Positioning to file : ";
	char	err1d[1024] = "Could not open file in present directory: file_";
	char	err2d[1024] = "Could not position to record : ";
	char	err1[1024]="*** ERROR *** Could not close Exabyte/Disc device file";
	char	errd[1024]="*** ERROR *** Could not open any disc reduc_0-999 in present directory";

	typep    = messp + tapetype_off;
	filerecp = messp + filerec_off;
	stor1p   = messp + stor1_off;
	stor2p   = messp + stor2_off;

	type = 0;
	if (inout == 1) type = *typep / 10;
	if (inout == 2) type = *typep - (*typep / 10) * 10;

	if ( type == 0 ) {
	   blockfac = REC_IN_BUF;			/* SIRIUS format, 4 32k blocks per databuffer */
	}
	if ( type == 1 && inout == 0 ) {
	   blockfac = 64;					/* DAISY input format, 64 1k blocks per databuffer */
	} else {
	   blockfac = REC_IN_BUF;			/* Always SIRIUS output format */
	}
	if ( type == 3 ) {
	   blockfac = REC_IN_BUF;			/* DISK format = SIRIUS format, see above */
	}
	  
	if ( inout == 1 ) {
	   exades = *stor1p;
	}
	if ( inout == 2 ) {
	   exades = *stor2p;
	}

/* Determining current file and record for disk */
	if ( type == 3 && inout == 1) {
		if (exades > 0) {
			current_file = *filerecp / 1000000;
			current_rec  = *filerecp - current_file * 1000000;
		} else {
			current_file = -1;
			current_rec  = 0;
			*filerecp    = 0;
		}
	}
	if ( type == 3 && inout == 2) {
		if (exades > 0) {
/*		  bytepos = tell( exades );*/
		  if(lseek(exades, bytepos, 0) == -1){         
		  				errprint("Could not find current position for output file, recordno set = 0");
				bytepos = 0;
			}

			current_rec  = bytepos / (blockfac * 32 * 1024); 
			current_file = outfileno;
		} else {
			outfileno    = -1;
			current_file =  outfileno;
			current_rec  =  0;
		}
	}

/* -------------------------------------------------- */
	/* CALL OPTION - Current position */
	if ( cup == 1 && type != 3) {
	   mt_command.mt_op = MTNOP;
	   if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	      return -1;
           }  
	   if (ioctl( exades, MTIOCGET, (char *)&mt_status) == -1) {
	      return -1;
           } 

	   wprint( "%s%d/%d\n", msg1, mt_status.mt_fileno, mt_status.mt_blkno/blockfac ); 

      	   return 0;
	}
	if ( cup == 1 && type == 3 ) {
	   wprint( "%s%d/%d\n", msg1, current_file, current_rec ); 

      	   return 0;
	}


	/* -------------------------------------------------- */
	/* CALL OPTION - BOT */
	/* Go to beginning of tape */
	if ( bot == 1 && type != 3) {
	   wprint( "%s\n",msg2 );
           sleep(1);
	   mt_command.mt_op = MTREW;
	   if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	      return -1;
           }          
      	   return 0;
	}

	/* Not in use */
	if ( bot == 1 && type == 3) {
	   errprint( "%s\n",err0d );
      	   return 0;
	}


	/* -------------------------------------------------- */
	/* CALL OPTION - EOD */
	/* Go to end of recorded data */
	if ( eod == 1 && type != 3) {
	   wprint( "%s\n",msg3 );
           sleep(1);
	   mt_command.mt_op = MTEOM;
	   if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	      return -1;
           }          
      	   return 0;
	}

	/* Go to end of recorded data */
	if ( eod == 1 && type == 3) {
	   errprint( "%s\n",err0d );
      	   return 0;
	}


	/* -------------------------------------------------- */
	/* CALL OPTION - POS FILE/REC */
	/* Read the status */

        if ( type != 3) {              /* Case of exabyte-files */
	   mt_command.mt_op = MTNOP;
	   if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	      return -1;
           }  
	   if (ioctl( exades, MTIOCGET, (char *)&mt_status) == -1) {
	      return -1;
           } 

	   current_file = mt_status.mt_fileno;
	   current_rec  = mt_status.mt_blkno;           
           if (fileno  == -1) fileno = current_file;
	   files2skip   = fileno - current_file;
	   recs2skip    = (recno * blockfac) - current_rec;


	   /* Case 1: Move to File x, Record 0 */
	   if ( files2skip != 0 && recno == 0 ) {
	      wprint( "%s%d\n",msg4, fileno );
              sleep(1);
	      mt_command.mt_op = MTFSF;
	      mt_command.mt_count = files2skip;
	      if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	         return -1;
              }           
      	      return 0;
	   }



		/* Case 2: Move first to File x Rec 0, Then to Record y */
		/* Not Used in current version !                        */
		if ( files2skip != 0 && recno != 0 ) {

	      mt_command.mt_op = MTFSF;
	      mt_command.mt_count = files2skip;
	      if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	         return -1;
              }           
	      mt_command.mt_op = MTFSR;
	      mt_command.mt_count = recno * blockfac;
	      if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	         return -1;
              }    
	      return 0;       
	   }

	
	   /* Case 3: Move to Record x in current file */
	   /* OK for offline sort !                    */
	   if ( files2skip == 0 && recs2skip != 0 ) {
	      mt_command.mt_op = MTFSR;
	      mt_command.mt_count = recs2skip;
	      if (ioctl( exades, MTIOCTOP, &mt_command) == -1) {
	         return -1;
              }           
      	      return 0;
	   }


	   /* Case 4: Don't do anything at all ... */
	   if ( files2skip == 0 && recs2skip == 0 ) {
	      wprint( "%s%d %d\n", msg1, mt_status.mt_fileno, mt_status.mt_blkno/blockfac );
	   }
	}   
	
	if ( type == 3) {										/* Case of disk-files */
		if (fileno == -1) fileno = current_file;
	   files2skip   = fileno - current_file;
	   recs2skip    = recno  - current_rec;
		if ( files2skip == 0 && recs2skip == 0 ){
	      wprint( "%s%d %d\n", msg1, fileno, recno );
		} else {
		if(inout == 1) {
			number2string(fileno, s1);						/* Move to fileno and recno */
			sprintf(in_file,"file_%s",s1);
			if ((exades = open(in_file,O_RDONLY)) == -1) {	/* file do not exist */
				errprint("%s%d\n",err1d,fileno);
				return -1;
			} else {
				bytepos = (blockfac*32*1024) * recno;
	            if(lseek(exades, bytepos, 0) == -1){        /* record do not exist */
						errprint("%s %d\n",err2d,recno);
						exades=0;
						return -1;
					}  else {
	               wprint( "%s%d/%d\n", msg1, fileno, recno ); 
						*filerecp  = fileno * 1000000 + recno;
						close(*stor1p);
						*stor1p    = exades;
						return 0;
					}
				}
			}

			if (inout == 2) {
				number2string(fileno, s1);					/* Move to fileno and recno */
				sprintf(out_file,"reduc_%s",s1);
				if ((exades = open(out_file,O_RDWR)) != -1) { /* file exist */
					errprint("Warning, you are writing to existing file: %s\n",out_file);
					type      = *typep / 10;
					*typep    = type * 10 + 3;				/* disk is output device  */
				} else {
					if ( *stor2p > 0){
						wprint("Closing files/rewinding...\n");
						sleep(1);
						if ( close( *stor2p ) == -1) {
							errprint("%s\n",err1);
						}
					}
					created = -1;
					for (n = 0; n < 1000; n++){				/*Finding last filenumber used*/
						number2string(n, s1);
						sprintf(out_file,"reduc_%s",s1);
						if ((exades = open(out_file,O_RDWR)) == -1) { /* file non-exists */
							created  = 1;
							break;
						}
					}
					
					if ( created == -1){
						errprint("%s\n",errd);
						exades  = 0;
						type    = *typep / 10;
						*typep  = type * 10 + 0;
					} else {								/* create a new file reduc_0 */
						if ((exades = creat(out_file,PERMS)) == -1) {
							wprint("Could not create outfile %s\n",out_file);
						} 
						exades = open(out_file,O_RDWR);
						type      = *typep / 10;
						*typep    = type * 10 + 3;           /* disk is output device  */
						outfileno = n;
						recno     = 0;
					} 
				}
				bytepos = (blockfac*32*1024) * recno;
	         if(lseek(exades,bytepos,0) == -1){				/* record do not exist */
					errprint("%s %d\n",err2d,recno);
					exades = 0;
					return -1;
				}  else {
	            wprint( "%s%d/%d\n", msg1, fileno, recno ); 
					outfileno = fileno;
					close(*stor2p);
					*stor2p   = exades;
					return 0;
				}
			}
		}
	}
}
void
MultiscaleAlgorithmAitken::subIterate()
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream ( 8011 ) << "MultiscaleAlgorithmAitken::subIterate() \n";
#endif

    multiscaleAlgorithm_Type::subIterate();

    // Verify tolerance
    if ( checkResidual ( 0 ) )
    {
        return;
    }

    M_multiscale->exportCouplingVariables ( *M_couplingVariables );

    M_generalizedAitken.restart();

    // Temporary Computation of a Block Vector - Testing purpose
    //    VectorType blocksVector( M_couplingVariables ); blocksVector = 0.0;
    //    for ( UInt i = 1 ; i < blocksVector.size() ; i = i+2)
    //        blocksVector[i] = 1.0;
    //    std::cout << "blocksVector: " << std::endl;
    //    blocksVector.showMe();

    for ( UInt subIT = 1; subIT <= M_subiterationsMaximumNumber; ++subIT )
    {
        // Update Coupling Variables
        switch ( M_method )
        {
            case Scalar:

                *M_couplingVariables += M_generalizedAitken.computeDeltaLambdaScalar ( *M_couplingVariables, *M_couplingResiduals );

                break;

            case Vectorial:

                *M_couplingVariables += M_generalizedAitken.computeDeltaLambdaVector ( *M_couplingVariables, *M_couplingResiduals, true );

                break;

            case VectorialBlock:

                //*M_couplingVariables += M_generalizedAitken.computeDeltaLambdaVectorBlock( *M_couplingVariables, *M_couplingResiduals, blocksVector, 2 );

                break;
        }

        // Import Coupling Variables inside the coupling blocks
        M_multiscale->importCouplingVariables ( *M_couplingVariables );

        // Verify tolerance
        if ( checkResidual ( subIT ) )
        {
            return;
        }
    }

    save ( M_subiterationsMaximumNumber, M_couplingResiduals->norm2() );

    multiscaleErrorCheck ( Tolerance, "Aitken algorithm residual: " + number2string ( M_couplingResiduals->norm2() ) +
                           " (required: " + number2string ( M_tolerance ) + ")\n", M_multiscale->communicator() == 0  );
}
int offline_start( ) 
{
	const char	*startsort = "/Applications/sirius/bin/startoffsort &";

	int		sort_off     = 0;
	int		time_off     = 1;
	int		offl_off     = 4;
	int		recc_off     = 5;
	int		badr_off     = 6;
	int		retstat_off  = 9;
 	int		tapetype_off = 3;
	int		filerec_off  = 13;
	int		filedes_off  = 2;

	int		*sortp;
	int		*timep;
 	int		*offlp;
	int		*reccp;
	int		*badrp;
	int		*retstatp;
	int		*typep;
	int		*filerecp;
	int		*filedesp;

	int			blockfac;
	int			current_file, current_rec;
	long int	bytepos;
	char		s1[4];
	char		in_file[128];         /* file names */ 
	char		err1d[1024] = "Could not open file in present directory: file_";
	char		err2d[1024] = "Could not position to record : ";
	char		msg[1024] = "Off-line sorting started ";
	char		err2[1024]= "*** ERROR *** Start of offline_sort failed"; 

	time_t		*tp;
	time_t		syst;

	tp			= (void *) malloc(4);
	syst		= time(tp);

	typep		= messp + tapetype_off;
	filerecp	= messp + filerec_off;
	sortp		= messp + sort_off;
	timep		= messp + time_off;
	offlp		= messp + offl_off;
	reccp		= messp + recc_off;
	badrp		= messp + badr_off;
	retstatp	= messp + retstat_off;
	filedesp	= messp + filedes_off;

	/* Put message box flags to start values */
	*sortp		= 0;
	*timep		= (int) tp;
	*offlp		= 1;
	*reccp		= 0;
	*badrp		= 0;
	*retstatp	= 0;
      
/* Precaution made for disk-file in case exades not defined */
	if (*typep == 3){
		close(exades);   
		blockfac = REC_IN_BUF;               /* DISK format = SIRIUS format */
		current_file = *filerecp/1000000;
		current_rec  = *filerecp - current_file*1000000;
		number2string(current_file, s1);                     /* Move to File*/
		sprintf(in_file,"file_%s",s1);
		if ((exades = open(in_file,O_RDONLY)) == -1) { /* file do not exist */
			errprint("%s%d\n",err1d,current_file);
			exades    = 0;
			*filedesp = exades;
			return -1;
		} else {
			bytepos = (blockfac*32*1024)*current_rec;
	      if(lseek(exades,bytepos,0) == -1){        /* record do not exist */
				errprint("%s %d\n",err2d,current_rec);
				exades    = 0;
				*filedesp = exades;
				return -1;
			} 
		}
		*filedesp = exades;
	}

/*  Activate the sorting task */
	if ( system( startsort ) == -1) {
		errprint("%s\n",err2);
		return -1;
	}  

	wprint("%s %s",msg,asctime(localtime(tp)));
	return 0;
}
void
MultiscaleModelMultiscale::saveSolution()
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream ( 8110 ) << "MultiscaleModelMultiscale::saveSolution() \n";
#endif

    for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
    {
        ( *i )->saveSolution();
    }

    for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
    {
        ( *i )->saveSolution();
    }

    // Save the framework numbering
    if ( M_globalData->dataTime()->isFirstTimeStep() )
    {
        // File name
        std::string filename = multiscaleProblemFolder + multiscaleProblemPrefix + "_Model_" + number2string ( M_ID ) + "_" + number2string ( multiscaleProblemStep ) + ".mfile";

        // Remove the old file if present
        if ( M_comm->MyPID() == 0 )
        {
            std::remove ( filename.c_str() );
        }

        M_comm->Barrier();

        // Open the file
        std::ofstream output;
        output.open ( filename.c_str(), std::ios::app );

        // Models list
        for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
            if ( ( *i )->communicator()->MyPID() == 0 )
            {
                output << "Model ID: " << ( *i )->ID() << ", Name: " << ( *i )->modelName() << std::endl;
            }

        M_comm->Barrier();

        // Couplings list
        if ( M_comm->MyPID() == 0 )
            for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
            {
                output << "Coupling ID: " << ( *i )->ID() << ", Name: " << ( *i )->couplingName() << std::endl;
            }

        // Close the file
        output.close();
    }
}
int offline_storage( int device )
{
	int		*typep;
	int		tapetype_off = 3;
	int		stor_off = 2;
	int		*storp;
	int		*filerecp;
	char	none[1024]="Data input NONE, select Exabyte 1/2 or Disk before start";
	char	exb1[1024]="Data input from Exabyte 1 (dev/rmt/0) selected";
	char	exb2[1024]="Data input from Exabyte 2 (dev/rmt/1) selected";
	char	err[1024] ="*** ERROR *** Could not open Exabyte device file";
	char	err1[1024]="*** ERROR *** Could not close Exabyte/Disk device file";
	char	disk[1024]="Data input from disk selected, filename: ";
	char	errd[1024]="*** ERROR *** Could not open any disk file_0-999 in present directory";

	int		n, created;
	char	s1[4];
	char	in_file[128];					/* file name from disk file_0, file_1, ... */ 
	storp    = messp + stor_off;
	typep    = messp + tapetype_off;
	filerecp = messp + 13;

	if ( device == 0 ) {
		if (exades > 0){
			wprint("Closing files/rewinding...\n");
			sleep(1);
			if ( close( exades ) == -1) {
				errprint("%s\n",err1);
			}
		}
		wprint("%s\n",none);
		exades = 0;
		*storp = exades;
		*typep = 0;
	} 

	if ( device == 1 ) {
      if (exades > 0){
         wprint("Closing files/rewinding...\n");
         sleep(1);
			if ( close( exades ) == -1) {
				errprint("%s\n",err1);
			}
		}
  		if ((exades = open("/dev/rmt/0n",O_RDONLY)) == -1) {
		   exades = 0;
		   errprint("%s\n",err);
     		}  else {
				wprint("%s\n",exb1);
			} 
			*storp = exades;
			*typep = 0;
			if ( exades > 0 ) {
				return 0;
			}  else {
			return -1;
		} 
	}

	if ( device == 2 ) {
		if (exades > 0){
			wprint("Closing files/rewinding...\n");
			sleep(1);
			if ( close( exades ) == -1) {
				errprint("%s\n",err1);
			}
		}
		if ((exades = open("/dev/rmt/1n",O_RDONLY)) == -1) {
			exades = 0;
			errprint("%s\n",err);
		} else {
			wprint("%s\n",exb2);
		} 
		*storp = exades;
		*typep = 0;

		if ( exades > 0 ) {
			return 0;
			}  else {
			return -1;
		} 
	}
		  
	if ( device == 3 ) {
		if (exades > 0){
			wprint("Closing files/rewinding...\n");
			sleep(1);
			if ( close( exades ) == -1) {
				errprint("%s\n",err1);
			}
		}
		created = -1;
		for( n = 0; n < 1000; n++){                  /*Finding first filenumber used*/
			number2string(n, s1);
			sprintf(in_file,"file_%s",s1);
			if ((exades = open(in_file,O_RDONLY)) != -1) {       /* file exists */
				created   = 1;
				break;
				}
				close(exades);
			}
			if(created == -1){
				errprint("%s\n",errd);
				exades = 0;
				*storp = exades;
				*typep = 0;
			} else {
			wprint("%s %s\n",disk,in_file);
				*filerecp = n*1000000;
				*storp    = exades;
				*typep    = 3;                                 /* disk is input device  */
			} 
		if ( exades > 0 ) {
			return 0;
		}  else {
		return -1;
		} 
	}
	return 0;
}
Example #13
0
// ===================================================
// MultiscaleModel Methods
// ===================================================
void
MultiscaleModelFSI1D::setupData ( const std::string& fileName )
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream ( 8130 ) << "MultiscaleModelFSI1D::setupData( fileName ) \n";
#endif

    multiscaleModel_Type::setupData ( fileName );

    GetPot dataFile ( fileName );

    M_data->setup ( dataFile );
    if ( M_globalData.get() )
    {
        setupGlobalData ( fileName );
    }

    //1D Model Physics
    M_physics = physicsPtr_Type ( physics_Type::factoryPhysics_Type::instance().createObject ( M_data->physicsType(), OneDFSI::physicsMap ) );
    M_physics->setData ( M_data );

    //1D Model Flux
    M_flux = fluxPtr_Type ( flux_Type::factoryFlux_Type::instance().createObject ( M_data->fluxType(), OneDFSI::fluxMap ) );
    M_flux->setPhysics ( M_physics );

    //1D Model Source
    M_source = sourcePtr_Type ( source_Type::factorySource_Type::instance().createObject ( M_data->sourceType(), OneDFSI::sourceMap ) );
    M_source->setPhysics ( M_physics );

    //Linear Solver
    M_linearSolver.reset ( new linearSolver_Type ( M_comm ) );
    //M_linearSolver->setupPreconditioner( dataFile, "1D_Model/prec" );
    M_linearSolver->setDataFromGetPot ( dataFile, "1D_Model/solver" );
    M_linearSolver->setParameter ( "Verbose", false );
    M_linearSolver->setParameters();

    //Linear Viscoelastic Solver
    if ( M_data->viscoelasticWall() )
    {
        M_linearViscoelasticSolver.reset ( new linearSolver_Type ( M_comm ) );
        M_linearViscoelasticSolver->setParametersList ( M_linearSolver->parametersList() );
        M_linearViscoelasticSolver->setParameters();
    }

    //1D Model Solver
    M_solver->setCommunicator ( M_comm );
    M_solver->setProblem ( M_physics, M_flux, M_source );
    M_solver->setLinearSolver ( M_linearSolver );
    M_solver->setLinearViscoelasticSolver ( M_linearViscoelasticSolver );

    //BC - We need to create the BCHandler before using it
    M_bc->createHandler();
    //M_bc->fillHandler( fileName, "1D_Model" );

    //Exporters
    M_data->setPostprocessingDirectory ( multiscaleProblemFolder );
    M_data->setPostprocessingFile ( multiscaleProblemPrefix + "_Model_" + number2string ( M_ID ) + "_" + number2string ( multiscaleProblemStep ) );

#ifdef HAVE_HDF5
    M_exporterMesh->setComm ( M_comm );
    regularMesh1D ( *M_exporterMesh, 1, M_data->numberOfElements(), false, M_data->length(), 0 );

    M_exporter->setDataFromGetPot ( dataFile );
    M_exporter->setPrefix ( multiscaleProblemPrefix + "_Model_" + number2string ( M_ID ) + "_" + number2string ( multiscaleProblemStep ) );
    M_exporter->setPostDir ( multiscaleProblemFolder );

    M_importer->setDataFromGetPot ( dataFile );
    M_importer->setPrefix ( multiscaleProblemPrefix + "_Model_" + number2string ( M_ID ) + "_" + number2string ( multiscaleProblemStep - 1 ) );
    M_importer->setPostDir ( multiscaleProblemFolder );
#endif

}