void _lucViewport_Print( void* viewport, Stream* stream ) { lucViewport* self = viewport; Journal_Printf( stream, "lucViewport: %s\n", self->name ); Stream_Indent( stream ); /* Print Parent */ _Stg_Component_Print( self, stream ); lucDrawingObject_Register_PrintAllObjects( self->drawingObject_Register, stream ); Stg_Class_Print( self->camera, stream ); Journal_PrintValue( stream, self->margin ); Journal_PrintValue( stream, self->nearClipPlane ); Journal_PrintValue( stream, self->farClipPlane ); Journal_PrintString( stream, self->title ); Journal_PrintBool( stream, self->timestep ); Journal_PrintBool( stream, self->disabled ); Stream_UnIndent( stream ); }
void testConstitutiveMatrix( FiniteElementContext* context ) { Stream* stream; SymmetricTensor stress; SymmetricTensor strainRate = {1, 2, 3, 4, 5, 6}; ConstitutiveMatrix* constitutiveMatrix; Journal_Enable_AllTypedStream( True ); stream = Journal_Register( Info_Type, (Name)"testConstitutiveMatrix" ); constitutiveMatrix = (ConstitutiveMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"constitutiveMatrix" ); /* Create Constitutive Matrix */ Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "output.dat" ); Journal_Printf( stream, "Constitutive Matrix after initialisation.\n" ); Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithThrees'.\n" ); ConstitutiveMatrix_SetValueInAllEntries( constitutiveMatrix, 3.0 ); ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream ); Journal_PrintBool( stream, constitutiveMatrix->isDiagonal ); ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress ); Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim ); Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim ); Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithViscosity7'.\n" ); ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, 7.0 ); ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream ); Journal_PrintBool( stream, constitutiveMatrix->isDiagonal ); Journal_Printf( stream, "Viscosity = %4g\n", ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix ) ); ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress ); Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim ); Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim ); constitutiveMatrix->isDiagonal = False; ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress ); Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim ); Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithSecondViscosity2'.\n" ); SetMatrixWithSecondViscosity2( constitutiveMatrix, 0, 0, NULL ); ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream ); Journal_PrintBool( stream, constitutiveMatrix->isDiagonal ); ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress ); Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim ); Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim ); Journal_Enable_AllTypedStream( False ); }
void _FieldVariable_Print( void* _fieldVariable, Stream* stream ) { FieldVariable* self = (FieldVariable*) _fieldVariable; Journal_Printf( stream, "FieldVariable - '%s'\n", self->name ); Stream_Indent( stream ); _Stg_Component_Print( self, stream ); Journal_PrintPointer( stream, self->_interpolateValueAt ); Journal_PrintPointer( stream, self->_getMinGlobalFieldMagnitude ); Journal_PrintPointer( stream, self->_getMaxGlobalFieldMagnitude ); Journal_PrintPointer( stream, self->_cacheMinMaxGlobalFieldMagnitude ); Journal_PrintPointer( stream, self->_getMinAndMaxLocalCoords ); Journal_PrintPointer( stream, self->_getMinAndMaxGlobalCoords ); Journal_PrintValue( stream, self->fieldComponentCount ); Journal_PrintValue( stream, self->dim ); Journal_PrintBool( stream, self->isCheckpointedAndReloaded); #ifdef LAM_MPI Journal_PrintPointer( stream, self->communicator ); #elif defined( OPEN_MPI ) Journal_PrintPointer( stream, self->communicator ); #else Journal_PrintValue( stream, self->communicator ); #endif Journal_PrintPointer( stream, self->fieldVariable_Register ); Stream_UnIndent( stream ); }
void TimeIntegrationSuite_TestDriver( TimeIntegrationSuiteData* data, char *_name, char *_DerivName0, char *_DerivName1, int _order ) { Stg_ComponentFactory* cf; Stream* stream; Dictionary* dictionary; TimeIntegrator* timeIntegrator; TimeIntegrand* timeIntegrand; TimeIntegrand* timeIntegrandList[2]; DomainContext* context; Variable* variable; Variable* variableList[2]; double* array; double* array2; Index size0 = 11; Index size1 = 7; Index array_I; Index timestep = 0; Index maxTimesteps = 10; Bool simultaneous; unsigned order; double error = 0.0; Name derivName; double tolerance = 0.001; Index integrand_I; Index integrandCount = 2; char expected_file[PCU_PATH_MAX]; dictionary = Dictionary_New(); Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") ); Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName0", Dictionary_Entry_Value_FromString(_DerivName0) ); Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName1", Dictionary_Entry_Value_FromString(_DerivName1) ); context = DomainContext_New( "context", 0, 0, MPI_COMM_WORLD, NULL ); cf = stgMainConstruct( dictionary, NULL, data->comm, context ); stgMainBuildAndInitialise( cf ); ContextEP_Append( context, AbstractContext_EP_Dt, TimeIntegrationSuite_GetDt ); /* Create Stuff */ order = _order; simultaneous = False; variableList[0] = Variable_NewVector( "testVariable", (AbstractContext*)context, Variable_DataType_Double, 2, &size0, NULL, (void**)&array, NULL ); variableList[1] = Variable_NewVector( "testVariable2", (AbstractContext*)context, Variable_DataType_Double, 2, &size1, NULL, (void**)&array2, NULL ); timeIntegrator = TimeIntegrator_New( "testTimeIntegrator", order, simultaneous, NULL, NULL ); timeIntegrator->context = context; timeIntegrandList[0] = TimeIntegrand_New( "testTimeIntegrand0", context, timeIntegrator, variableList[0], 0, NULL, True ); timeIntegrandList[1] = TimeIntegrand_New( "testTimeIntegrand1", context, timeIntegrator, variableList[1], 0, NULL, True ); Journal_Enable_AllTypedStream( True ); stream = Journal_Register( Info_Type, (Name)"EulerStream" ); Stream_RedirectFile( stream, _name ); Stream_Enable( timeIntegrator->info, False ); derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName0" ); timeIntegrandList[0]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName ); Journal_Printf( stream, "DerivName0 - %s\n", derivName ); derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName1" ); timeIntegrandList[1]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName ); Journal_Printf( stream, "DerivName1 - %s\n", derivName ); /* Print Stuff to file */ Journal_PrintValue( stream, order ); Journal_PrintBool( stream, simultaneous ); /* Add stuff to EPs */ TimeIntegrator_AppendSetupEP( timeIntegrator, "start1", TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context ); TimeIntegrator_AppendFinishEP( timeIntegrator, "finish1", TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] ); TimeIntegrator_PrependSetupEP( timeIntegrator, "start0", TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] ); TimeIntegrator_PrependFinishEP( timeIntegrator, "finish0", TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context ); /* Build */ Stg_Component_Build( variableList[0], context, False ); Stg_Component_Build( variableList[1], context, False ); Stg_Component_Build( timeIntegrator, context, False ); Stg_Component_Build( timeIntegrandList[0], context, False ); Stg_Component_Build( timeIntegrandList[1], context, False ); array = Memory_Alloc_Array( double, 2 * size0, "name" ); array2 = Memory_Alloc_Array( double, 2 * size1, "name" ); /* Initialise */ memset( array, 0, sizeof(double) * 2 * size0 ); memset( array2, 0, sizeof(double) * 2 * size1 ); Stg_Component_Initialise( timeIntegrator, context, False ); Stg_Component_Initialise( variableList[0], context, False ); Stg_Component_Initialise( variableList[1], context, False ); Stg_Component_Initialise( timeIntegrandList[0], context, False ); Stg_Component_Initialise( timeIntegrandList[1], context, False ); for ( timestep = 0.0 ; timestep < maxTimesteps ; timestep ++ ) { Journal_Printf( stream, "Step %u - Time = %.3g\n", timestep, context->currentTime ); Stg_Component_Execute( timeIntegrator, context, True ); context->currentTime += AbstractContext_Dt( context ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { timeIntegrand = timeIntegrandList[ integrand_I ]; variable = variableList[ integrand_I ]; for ( array_I = 0 ; array_I < variable->arraySize ; array_I++ ) { if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * context->currentTime ); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * context->currentTime ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * context->currentTime ); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3 * array_I * context->currentTime ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - array_I * context->currentTime * context->currentTime ); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + 0.5 * array_I * context->currentTime * context->currentTime ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.25 * array_I * context->currentTime * context->currentTime ); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 1.5 * array_I * context->currentTime * context->currentTime ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0)); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0)); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) { error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0)); error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0)); } else Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME ), "Don't understand _calculateTimeDeriv = %p\n", timeIntegrand->_calculateTimeDeriv ); } } } pcu_check_lt( error, tolerance ); if ( error < tolerance ) Journal_Printf( stream, "Passed\n" ); else Journal_Printf( stream, "Failed - Error = %lf\n", error ); Journal_Enable_AllTypedStream( False ); if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) { pcu_filename_expected( "testTimeIntegrationEulerOutput.expected", expected_file ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) { pcu_filename_expected( "testTimeIntegrationRK2Output.expected", expected_file ); } else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) { pcu_filename_expected( "testTimeIntegrationRK4Output.expected", expected_file ); } pcu_check_fileEq( _name, expected_file ); /* Destroy stuff */ Stream_CloseAndFreeFile( stream ); Memory_Free( array ); Memory_Free( array2 ); Stg_Class_Delete( variable ); _Stg_Component_Delete( timeIntegrator ); _Stg_Component_Delete( timeIntegrandList[0] ); _Stg_Component_Delete( timeIntegrandList[1] ); remove( _name ); }