Пример #1
0
DWORD
_cdecl
main(
    int argc,
    char *argv[],
    char *envp[]
    )
{
    char Drive[MAX_PATH];
    HANDLE hDrive, hDiskImage;
    DISK_GEOMETRY Geometry;
    UINT i;
    char c, *p;
    LPSTR DriveName;
    BOOL fUsage = TRUE;
    BOOL fShowGeometry = FALSE;
    BOOL fDiskImage = FALSE;
    BOOL SourceIsDrive;
    LPSTR Source, Destination, DiskImage;

    if ( argc > 1 ) {
        fUsage = FALSE;
        while (--argc) {
            p = *++argv;
            if (*p == '/' || *p == '-') {
                while (c = *++p)
                switch (toupper( c )) {
                case '?':
                    fUsage = TRUE;
                    break;

                case 'C':
                    fDiskImage = TRUE;
                    argc--, argv++;
                    Source = *argv;
                    argc--, argv++;
                    Destination = *argv;
                    break;

                case 'G':
                    fShowGeometry = TRUE;
                    argc--, argv++;
                    DriveName = *argv;
                    break;

                default:
                    printf("MFMT: Invalid switch - /%c\n", c );
                    fUsage = TRUE;
                    break;
                    }
                }
            }
        }

    if ( fUsage ) {
        printf("usage: MFMT switches \n" );
        printf("            [-?] display this message\n" );
        printf("            [-g drive] shows disk geometry\n" );
        printf("            [-c source destination] produce diskimage\n" );
        ExitProcess(1);
        }

    if ( fShowGeometry ) {
        sprintf(Drive,"\\\\.\\%s",DriveName);
        hDrive = CreateFile(
                    Drive,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    0,
                    NULL
                    );
        if ( hDrive == INVALID_HANDLE_VALUE ) {
            printf("MFMT: Open %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }

        LockVolume(hDrive);

        if ( !GetDiskGeometry(hDrive,&Geometry) ) {
            printf("MFMT: GetDiskGeometry %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }
        PrintGeometry(DriveName,&Geometry);

        if ( !GetSupportedGeometrys(hDrive) ) {
            printf("MFMT: GetSupportedGeometrys %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }
        printf("\nDrive %s supports the following disk geometries\n",DriveName);

        for(i=0;i<SupportedGeometryCount;i++) {
            printf("\n");
            PrintGeometry(NULL,&SupportedGeometry[i]);
            }

        printf("\n");
        ExitProcess(0);
        }

    if ( fDiskImage ) {
        SourceIsDrive = FALSE;
        if ( Source[strlen(Source)-1] == ':' ) {
            SourceIsDrive = TRUE;
            sprintf(Drive,"\\\\.\\%s",Source);
            DiskImage = Destination;
            }
        if ( Destination[strlen(Destination)-1] == ':' ) {
            if ( SourceIsDrive ) {
                printf("MFMT: Source and Destination cannot both be drives\n");
                ExitProcess(1);
                }
            SourceIsDrive = FALSE;
            sprintf(Drive,"\\\\.\\%s",Destination);
            DiskImage = Source;
            }
        else {
            if ( !SourceIsDrive ) {
                printf("MFMT: Either Source or Destination must be a drive\n");
                ExitProcess(1);
                }
            }

        //
        // Open and Lock the drive
        //

        hDrive = CreateFile(
                    Drive,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    0,
                    NULL
                    );
        if ( hDrive == INVALID_HANDLE_VALUE ) {
            printf("MFMT: Open %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }
        LockVolume(hDrive);

        if ( !GetDiskGeometry(hDrive,&Geometry) ) {
            printf("MFMT: GetDiskGeometry %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }

        if ( !GetSupportedGeometrys(hDrive) ) {
            printf("MFMT: GetSupportedGeometrys %s failed %d\n",DriveName,GetLastError());
            ExitProcess(1);
            }

        //
        // Open the disk image file
        //

        hDiskImage = CreateFile(
                        DiskImage,
                        GENERIC_READ | GENERIC_WRITE,
                        0,
                        NULL,
                        SourceIsDrive ? CREATE_ALWAYS : OPEN_EXISTING,
                        0,
                        NULL
                        );
        if ( hDiskImage == INVALID_HANDLE_VALUE ) {
            printf("MFMT: Open %s failed %d\n",DiskImage,GetLastError());
            ExitProcess(1);
            }

        //
        // Now do the copy
        //
        {
            LPVOID IoBuffer;
            BOOL b;
            DWORD BytesRead, BytesWritten;
            DWORD FileSize;
            DWORD GeometrySize;

            //
            // If we are copying from floppy to file, just do the copy
            // Otherwise, we might have to format the floppy first
            //

            if ( SourceIsDrive ) {

                //
                // Device reads must be sector aligned. VirtualAlloc will
                // garuntee alignment
                //

                GeometrySize = Geometry.Cylinders.LowPart *
                               Geometry.TracksPerCylinder *
                               Geometry.SectorsPerTrack *
                               Geometry.BytesPerSector;

                IoBuffer = VirtualAlloc(NULL,GeometrySize,MEM_COMMIT,PAGE_READWRITE);

                if ( !IoBuffer ) {
                    printf("MFMT: Buffer Allocation Failed\n");
                    ExitProcess(1);
                    }

                b = ReadFile(hDrive,IoBuffer, GeometrySize, &BytesRead, NULL);
                if (b && BytesRead){
                    b = WriteFile(hDiskImage,IoBuffer, BytesRead, &BytesWritten, NULL);
                    if ( !b || ( BytesRead != BytesWritten ) ) {
                        printf("MFMT: Fatal Write Error %d\n",GetLastError());
                        ExitProcess(1);
                        }
                    }
                else {
                    printf("MFMT: Fatal Read Error %d\n",GetLastError());
                    ExitProcess(1);
                    }
                }
            else {

                //
                // Check to see if the image will fit on the floppy. If it
                // will, then LowLevelFormat the floppy and press on
                //

                FileSize = GetFileSize(hDiskImage,NULL);

                b = FALSE;
                for(i=0;i<SupportedGeometryCount;i++) {
                    GeometrySize = SupportedGeometry[i].Cylinders.LowPart *
                                   SupportedGeometry[i].TracksPerCylinder *
                                   SupportedGeometry[i].SectorsPerTrack *
                                   SupportedGeometry[i].BytesPerSector;
                    if ( GeometrySize >= FileSize ) {

                        IoBuffer = VirtualAlloc(NULL,GeometrySize,MEM_COMMIT,PAGE_READWRITE);

                        if ( !IoBuffer ) {
                            printf("MFMT: Buffer Allocation Failed\n");
                            ExitProcess(1);
                            }

                        //
                        // Format the floppy
                        //

                        LowLevelFormat(hDrive,&SupportedGeometry[i]);

                        b = ReadFile(hDiskImage,IoBuffer, GeometrySize, &BytesRead, NULL);
                        if (b && BytesRead){
                            b = WriteFile(hDrive,IoBuffer, BytesRead, &BytesWritten, NULL);
                            if ( !b || ( BytesRead != BytesWritten ) ) {
                                printf("MFMT: Fatal Write Error %d\n",GetLastError());
                                ExitProcess(1);
                                }
                            }
                        else {
                            printf("MFMT: Fatal Read Error %d\n",GetLastError());
                            ExitProcess(1);
                            }
                        b = TRUE;
                        break;
                        }
                    }

                if ( !b ) {
                    printf("MFMT: FileSize %d is not supported on drive %s\n",FileSize,DriveName);
                    ExitProcess(1);
                    }
                }
        }

        //
        // Dismounting forces the filesystem to re-evaluate the media id
        // and geometry. This is the same as popping the floppy in and out
        // of the disk drive
        //

        DismountVolume(hDrive);
        UnlockVolume(hDrive);

        ExitProcess(0);
        }
}
Пример #2
0
void IntegrateFromGeometry()
{
    int i,j,k,CE,n=0;
    double Residual,sum=0.0,*ViewFactorRowScale,*R,*P,*AP;

    FILE *fp;

    for( i=0; i<NGeomElem; i++ )
    {
        Geometry[i].Area = BiCubicArea( &Geometry[i] );
        Geometry[i].Flags |= GEOMETRY_FLAG_LEAF;
    }

    for( i=0; i<NGeomElem; i++ )
    for( j=i; j<NGeomElem; j++ ) ComputeViewFactors( &Geometry[i],&Geometry[j],0,0,&CE );

    for( i=8; i<12; i++ ) PutValue( &Geometry[i],1.0 );

    for( i=0; i<NGeomElem; i++ ) NumerateLeaves( &Geometry[i] );

    R  = (double *)calloc( NMAX,sizeof(double) );
    P  = (double *)calloc( NMAX,sizeof(double) );
    AP = (double *)calloc( NMAX,sizeof(double) );
    ViewFactorRowScale = (double *)calloc( NMAX,sizeof(double) );

    for( i=0; i<NGeomElem; i++ ) ComputeViewFactorRowSums( &Geometry[i],0.0,ViewFactorRowScale );

#ifdef OUTPUT_EQU
    fprintf( stderr, "NMAX: %d\n", NMAX );

    A = (double *)calloc( NMAX*NMAX,sizeof(double) );
    Y = (double *)calloc( NMAX,sizeof(double) );
    S = (double *)calloc( NMAX,sizeof(double) );

    for( i=0; i<NGeomElem; i++ ) MakeMatrix( &Geometry[i] );

    for( i=0; i<NMAX; i++ ) fprintf( stderr, "ROWSUM1: %g\n", R[i] );

    for( i=0; i<NMAX; i++ )
    {
        sum = 0.0;
        for( j=0; j<NMAX; j++ ) sum += A[i*NMAX+j];
        fprintf( stderr, "ROWSUM2: %g\n", sum );
    }

    fprintf( stdout, "%d\n", NMAX );

    for( i=0; i<NMAX; i++ ) fprintf( stdout, "%g\n",S[i] );
    for( i=0; i<NMAX; i++ ) fprintf( stdout, "%g\n",Y[i] );

    for( i=0; i<NMAX; i++ )
    {
        for( j=0; j<NMAX; j++ )
        {
            if ( i==j )
                A[i*NMAX+j] = S[i]*(1-0.85*A[i*NMAX+j]/R[i]);
            else
                A[i*NMAX+j] = -0.85*A[i*NMAX+j]*S[i]/R[i];

            fprintf( stdout, "%g\n", A[i*NMAX+j] );
        }

        Y[i] *= S[i];
        S[i] =  0.0;
    }
#endif

#ifndef JACOB
{
double T,second(),Alpha,Beta,RNorm,R1Norm;
T = second();

#ifndef OUTPUT_EQU
    for( i=0; i<NGeomElem; i++ ) LinearSolveResidual( &Geometry[i],0.0,ViewFactorRowScale,R );
    for( i=0; i<NGeomElem; i++ ) LinearSolveUpdateB( &Geometry[i],0.0 );
    for( i=0; i<NGeomElem; i++ ) LinearSolveUpdateRP( &Geometry[i],0.0,0.0,R,AP );
#else
    for( i=0; i<NMAX; i++ ) { R[i] = Y[i]; P[i] = Y[i]; }
#endif

    for( j=0; j<200; j++ )
    {
#ifndef OUTPUT_EQU
        for( i=0; i<NGeomElem; i++ ) LinearSolveGather( &Geometry[i],0.0,ViewFactorRowScale,P,AP );
#else

        for( i=0; i<NMAX; i++ )
        {
             AP[i] = 0.0;
             for( k=0; k<NMAX; k++ ) AP[i] += A[i*NMAX+k]*P[k];
        }
#endif

        RNorm = R1Norm = Alpha = Beta = 0.0;

        for( i=0; i<NMAX; i++ ) RNorm += R[i]*R[i];
        for( i=0; i<NMAX; i++ ) Alpha += P[i]*AP[i];
        Alpha = RNorm/Alpha;

        for( i=0; i<NMAX; i++ ) R1Norm += (R[i]-Alpha*AP[i])*(R[i]-Alpha*AP[i]);
        Beta  = R1Norm/RNorm;

        fprintf( stderr, "ITERATION: %d, RES: %g,%g,%g,%g\n", j,R1Norm,Alpha,Beta,RNorm );

#ifdef OUTPUT_EQU
        for( i=0; i<NMAX; i++ ) S[i] += Alpha*P[i];
        for( i=0; i<NMAX; i++ ) R[i] -= Alpha*AP[i];
        for( i=0; i<NMAX; i++ ) P[i] = R[i] + Beta*P[i];
#else
        for( i=0; i<NGeomElem; i++ ) LinearSolveUpdateB( &Geometry[i],Alpha );
        for( i=0; i<NGeomElem; i++ ) LinearSolveUpdateRP( &Geometry[i],Alpha,Beta,R,AP );
#endif

        if ( R1Norm < 1.0E-11 || j==199 )
        {
            sprintf( str, "b%d.p", j );
            fp = fopen( str, "w" );
 
            n = 0;
            for( i=0; i<NGeomElem; i++ ) PrintGeometry(&Geometry[i],&n);

            fprintf( fp, "%d %d 1 1\n", n,n/4 );
            for( i=0; i<n; i++ )fprintf( fp, "%g %g %g\n",XX[i],YY[i],ZZ[i] );
            for( i=0; i<n/4; i++ )
            {
                fprintf( fp, "1 404 %d %d %d %d\n",4*i,4*i+1,4*i+2,4*i+3 );
            }

            for( i=0; i<n; i++ ) fprintf( fp, "%g\n", LL[i] );
            fclose( fp );

            break;
        }
    }
fprintf( stderr, "LINSOLVE TIME: %g\n", second()-T );
}
#else
{
double T,second();
T = second();
    for( j=0; j<200; j++ )
    {
        for( i=0; i<NGeomElem; i++ ) LinearSolveGather( &Geometry[i], 0.0, 0.0 );

        Residual = 0.0;
        for( i=0; i<NGeomElem; i++ ) LinearSolveUpdate( &Geometry[i],&Residual );
        fprintf( stderr, "ITERATION: %d, RES: %g\n", j,Residual );

        if ( Residual < 1.0E-11 || j==199  )
        {
            sprintf( str, "b%d.p", j );
            fp = fopen( str, "w" );
 
            n = 0;
            for( i=0; i<NGeomElem; i++ ) PrintGeometry(&Geometry[i],&n);

            fprintf( fp, "%d %d 1 1\n", n,n/4 );
            for( i=0; i<n; i++ )fprintf( fp, "%g %g %g\n",XX[i],YY[i],ZZ[i] );
            for( i=0; i<n/4; i++ )
            {
                fprintf( fp, "1 404 %d %d %d %d\n",4*i,4*i+1,4*i+2,4*i+3 );
            }

            for( i=0; i<n; i++ ) fprintf( fp, "%g\n", LL[i] );
            fclose( fp );

            break;
        }
    }
fprintf( stderr, "LINSOLVE TIME: %g\n", second()-T );
}
Пример #3
0
int main(int argc, char *argv[]){
    
    int p_order = 2;
    int n_threads = 0;
    TPZGeoMesh * gmesh = ReadGeometry();

#ifdef PZDEBUG
    PrintGeometry(gmesh);
#endif
    
    TPZCompMesh *cmesh      = CMeshFooting2D(gmesh, p_order);
    TPZAnalysis *analysis   = Analysis(cmesh,n_threads);
    
#ifdef USING_BOOST
    boost::posix_time::ptime post_proc_t1 = boost::posix_time::microsec_clock::local_time();
#endif
    
    /// Creation of a post-process analysis
    TPZPostProcAnalysis * post_processor = new TPZPostProcAnalysis;
    post_processor->SetCompMesh(cmesh);
    
    int n_regions = 1;
    TPZManVector<int,10> post_mat_id(n_regions);
    post_mat_id[0] = ERock;
    
    TPZStack<std::string> scalar_names,vector_names, tensor_names;
    vector_names.Push("Displacement");
    tensor_names.Push("Strain");
    tensor_names.Push("StrainPlastic");
    tensor_names.Push("Stress");
    
    TPZStack<std::string> var_names;
    for (auto i : scalar_names) {
        var_names.Push(i);
    }
    for (auto i : vector_names) {
        var_names.Push(i);
    }
    for (auto i : tensor_names) {
        var_names.Push(i);
    }
    
    post_processor->SetPostProcessVariables(post_mat_id, var_names);
    TPZFStructMatrix structmatrix(post_processor->Mesh());
    structmatrix.SetNumThreads(n_threads);
    post_processor->SetStructuralMatrix(structmatrix);
    
#ifdef USING_BOOST
    boost::posix_time::ptime post_proc_t2 = boost::posix_time::microsec_clock::local_time();
#endif
    
#ifdef USING_BOOST
    REAL case_solving_time = boost::numeric_cast<double>((post_proc_t2-post_proc_t1).total_milliseconds());
    std::cout << "Created post-processing in :" << setw(10) <<  case_solving_time/1000.0 << setw(5)   << " seconds." << std::endl;
    std::cout << std::endl;
#endif

#ifdef USING_BOOST
    boost::posix_time::ptime case_t1 = boost::posix_time::microsec_clock::local_time();
#endif
    
    std::string plotfile = "footing_elast.vtk";
    // For a single step
    REAL dt = 0.1;
    int n_steps = 10;
    for (int it = 1; it <= n_steps; it++) {
        
        REAL t = it*dt;
        LoadingRamp(t,cmesh);
        FindRoot(analysis);
        AcceptSolution(cmesh, analysis);
        
#ifdef USING_BOOST
        boost::posix_time::ptime post_l2_projection_proc_t1 = boost::posix_time::microsec_clock::local_time();
#endif
        post_processor->TransferSolution();
        
#ifdef USING_BOOST
        boost::posix_time::ptime post_l2_projection_proc_t2 = boost::posix_time::microsec_clock::local_time();
        REAL l2_projection_time = boost::numeric_cast<double>((post_l2_projection_proc_t2-post_l2_projection_proc_t1).total_milliseconds());
        std::cout << "L2 projection post-processing in :" << setw(10) <<  l2_projection_time/1000.0 << setw(5)   << " seconds." << std::endl;
        std::cout << std::endl;
#endif


#ifdef USING_BOOST
        boost::posix_time::ptime post_vtk_proc_t1 = boost::posix_time::microsec_clock::local_time();
#endif
        PostProcess(post_processor,scalar_names,vector_names,tensor_names,plotfile);
        
#ifdef USING_BOOST
        boost::posix_time::ptime post_vtk_proc_t2 = boost::posix_time::microsec_clock::local_time();
        REAL vtk_drawing_time = boost::numeric_cast<double>((post_vtk_proc_t2-post_vtk_proc_t1).total_milliseconds());
        std::cout << "Drawing vtk file in :" << setw(10) <<  vtk_drawing_time/1000.0 << setw(5)   << " seconds." << std::endl;
        std::cout << std::endl;
#endif
        
    }
    
#ifdef USING_BOOST
    boost::posix_time::ptime case_t2 = boost::posix_time::microsec_clock::local_time();
    REAL case_time = boost::numeric_cast<double>((case_t2-case_t1).total_milliseconds());
    std::cout << "Execution complete in :" << setw(10) <<  case_time/1000.0 << setw(5)   << " seconds." << std::endl;
    std::cout << std::endl;
#endif
    
    std::cout << "Execution complete." << std::endl;
	return 0;
}