示例#1
0
void _SwarmVariable_ValueAtFloat( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
	SwarmVariable*	self     = (SwarmVariable*)swarmVariable;
	Variable*       variable = self->variable;
	Dof_Index       dofCount = self->dofCount;
	Dof_Index       dof_I;

	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
		value[ dof_I ] = (double) Variable_GetValueAtFloat( variable, lParticle_I, dof_I );
	}
}
void VariableSuite_TestVariable_Float( VariableSuiteData* data ) {
    typedef float Triple[3];

    float* array;
    Triple* structArray;
    Index length = 10;

    float testValues[] = { 123456789.0, 0.987654321 };
    Index testValueCount = 2;
    Index test_I;
    float testValue;

    Variable* var;
    Variable* vec;
    Variable* vecVar[3];

    int i, j;

    array = Memory_Alloc_Array( float, length, "test" );
    structArray = Memory_Alloc_Array( Triple, length, "test" );

    var = Variable_NewScalar( "Float-Scalar", NULL, Variable_DataType_Float, &length, NULL, (void**)&array, data->vr );
    vec = Variable_NewVector( "Float-Three", NULL, Variable_DataType_Float, 3, &length, NULL, (void**)&structArray, data->vr, "a", "b", "c" );

    vecVar[0] = Variable_Register_GetByName( data->vr, "a" );
    vecVar[1] = Variable_Register_GetByName( data->vr, "b" );
    vecVar[2] = Variable_Register_GetByName( data->vr, "c" );

    Variable_Register_BuildAll( data->vr );

    for ( test_I = 0; test_I < testValueCount; ++test_I ) {
        testValue = testValues[test_I];

        for ( i = 0; i < length; ++i ) {
            Variable_SetValueFloat( var, i, testValue );

            Variable_SetValueAtFloat( vec, i, 0, testValue );
            Variable_SetValueAtFloat( vec, i, 1, testValue );
            Variable_SetValueAtFloat( vec, i, 2, testValue );
        }

        /* "~~~Scalar~~~\n" */
        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueFloat( var, i ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueFloatAsChar( var, i ) == (float)(char)testValue );
            pcu_check_true( Variable_GetValueFloatAsShort( var, i ) == (float)(short)testValue );
            pcu_check_true( Variable_GetValueFloatAsInt( var, i ) == (float)(int)testValue );
            pcu_check_true( Variable_GetValueFloatAsDouble( var, i ) == (double)(float)testValue );
        }

        /*~~~Vector~~~*/
        for ( i = 0; i < length; ++i ) {
            pcu_check_true( Variable_GetValueAtFloat( vec, i, 0 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 0 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 0 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 0 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 0 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 0 ) == &structArray[i][0] );

            pcu_check_true( Variable_GetValueAtFloat( vec, i, 1 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 1 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 1 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 1 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 1 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 1 ) == &structArray[i][1] );

            pcu_check_true( Variable_GetValueAtFloat( vec, i, 2 ) == (float)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsChar( vec, i, 2 ) == (char)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsShort( vec, i, 2 ) == (short)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsInt( vec, i, 2 ) == (int)(float)testValue );
            pcu_check_true( Variable_GetValueAtFloatAsDouble( vec, i, 2 ) == (double)(float)testValue );
            pcu_check_true( Variable_GetPtrAtFloat( vec, i, 2 ) == &structArray[i][2] );
        }

        /*~~~Vector: Sub-Variable~~~*/
        for ( i = 0; i < length; ++i ) {
            for ( j = 0; j < 3; ++j ) {
                pcu_check_true( Variable_GetStructPtr( vecVar[j], i ) == &structArray[i][j] );
            }
        }
    }
}