void _StGermain_VaryingCornerAttractors_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
	DomainContext*   context;

	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
	
	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_VaryingCornerAttractors_UpdatePositions );
}
void _StGermain_SingleAttractor_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
	DomainContext*   context;

	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
	Stream_SetPrintingRank( 
		Journal_Register( Info_Type, (Name)"Context"  ),
		Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
	
	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_SingleAttractor_UpdatePositions );
}
void TestHasYieldedFlagSuite_SwarmVariableList( TestHasYieldedFlagSuiteData* data ) {
	Dictionary*           dictionary;
	UnderworldContext*    context;
	Stg_ComponentFactory* cf;
	char                  expected_file[PCU_PATH_MAX], output_file[PCU_PATH_MAX];
	char                  xml_input[PCU_PATH_MAX];
	char                  rFile[PCU_PATH_MAX];
	int                   err;
	
	pcu_docstring( "This test makes sure there is a hasYielded flag on each particle if the materialSwarm is not NULL\n" );
	
	/* read in the xml input file */
	pcu_filename_input( "testHasYieldedFlag.xml", xml_input );
	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
	data->context = context;
	dictionary = context->dictionary;
	
	/* replace the Execute EP with the function to test the ConstitutiveMatrix */
	ContextEP_ReplaceAll( context, AbstractContext_EP_Execute, testHasYieldedFlag );
	
	/* build and initialise all components */
	stgMainBuildAndInitialise( cf );
	
	/* now run the all EPs */
	stgMainLoop( cf );
	
	/* create the expected file string */
	pcu_filename_expected( "testHasYieldedFlag_SwarmVariableList.expected", expected_file );
	
	/* create the string for the output.dat */
	strcpy( output_file, context->outputPath );
	strcat( output_file, "/SwarmVariables.list" );
	
	/* check the output file against the expected output file */
	pcu_check_fileEq( output_file, expected_file );
	
	/* Now clean output path */
	sprintf(rFile, "%s/SwarmVariables.list", data->context->outputPath );
	err = remove( rFile );
	if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
	
	/* end the run */
	stgMainDestroy( cf );
}
void SemiLagrangianIntegratorSuite_Test( SemiLagrangianIntegratorSuiteData* data ) {
   Stg_ComponentFactory*	cf;
   ConditionFunction*      condFunc;
   //char			xml_input[PCU_PATH_MAX];
   double			l2Error;
   FeVariable*		phiField;
   FeVariable*		phiOldField;
   Swarm*			gaussSwarm;
   double			phi[3];
   unsigned		node_i;
   AbstractContext*	context;

   //pcu_filename_input( "testSemiLagrangianIntegrator.xml", xml_input );
   cf = stgMainInitFromXML( "StgFEM/Utils/input/testSemiLagrangianIntegrator.xml", MPI_COMM_WORLD, NULL );
   context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, NULL  );

   condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_Line, (Name)"Line", NULL  );
   ConditionFunction_Register_Add( condFunc_Register, condFunc );
   condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_ShearCellX, (Name)"ShearCellX", NULL  );
   ConditionFunction_Register_Add( condFunc_Register, condFunc );
   condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_ShearCellY, (Name)"ShearCellY", NULL  );
   ConditionFunction_Register_Add( condFunc_Register, condFunc );

   /* manually set the timestep */
   ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, Dt );
   ContextEP_Append( context, AbstractContext_EP_UpdateClass, SemiLagrangianIntegratorSuite_UpdatePositions );

   stgMainBuildAndInitialise( cf );

   phiField = (FeVariable*)LiveComponentRegister_Get( cf->LCRegister, (Name)"PhiField" );
   phiOldField = (FeVariable* )LiveComponentRegister_Get( cf->LCRegister, (Name)"PhiFieldInitial" );
   gaussSwarm = (Swarm* )LiveComponentRegister_Get( cf->LCRegister, (Name)"gaussSwarm"  );
   for( node_i = 0; node_i < Mesh_GetLocalSize( phiField->feMesh, MT_VERTEX ); node_i++ ) {
      FeVariable_GetValueAtNode( phiField, node_i, phi );
      FeVariable_SetValueAtNode( phiOldField, node_i, phi );
   }

   stgMainLoop( cf );

   l2Error = SemiLagrangianIntegratorSuite_EvaluateError( phiField, phiOldField, gaussSwarm );

   pcu_check_true( l2Error < TOLERANCE );

   stgMainDestroy( cf );
}
void ConstitutiveMatrixSuite_CartesianMatrix2D( ConstitutiveMatrixSuiteData* data ) {
   UnderworldContext*    context;
   Stg_ComponentFactory* cf;
   char                  expected_file[PCU_PATH_MAX], output_file[PCU_PATH_MAX];
   char                  rFile[PCU_PATH_MAX];
   int                   err;

   pcu_docstring( "This test creates a 2D cartesian constitutive matrix data structure and tests its functionality against an expected file" );

   /* get the data structures created in the setup */
   cf = data->context->CF;
   context = data->context;

   /* replace the Execute EP with the function to test the ConstitutiveMatrix */
   ContextEP_ReplaceAll( context, AbstractContext_EP_Execute, testConstitutiveMatrix );

   /* build and initialise all components */
   stgMainBuildAndInitialise( cf );

   /* now run the all EPs */
   stgMainLoop( cf );

   /* create the expected file string */
   pcu_filename_expected( "testConstitutiveMatrix_Cartesian2D.expected", expected_file );

   /* create the string for the output.dat */
   strcpy( output_file, context->outputPath );
   strcat( output_file, "/output.dat" );

   /* check the output file against the expected output file */
   pcu_check_fileEq( output_file, expected_file );

   /* Now clean output path */
   sprintf(rFile, "%s/output.dat", data->context->outputPath );
   err = remove( rFile );
   if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);

}
Ejemplo n.º 6
0
int main( int argc, char* argv[] ) {
	MPI_Comm CommWorld;
	int rank;
	int numProcessors;
	int procToWatch;
	Dictionary* dictionary;
	AbstractContext* abstractContext;
	
	/* Initialise MPI, get world info */
	MPI_Init( &argc, &argv );
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size( CommWorld, &numProcessors );
	MPI_Comm_rank( CommWorld, &rank );
	
	BaseFoundation_Init( &argc, &argv );
	BaseIO_Init( &argc, &argv );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );
	BaseExtensibility_Init( &argc, &argv );
	BaseContext_Init( &argc, &argv );
	
	stream =  Journal_Register( InfoStream_Type, "myStream" );

	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) Journal_Printf( (void*) stream, "Watching rank: %i\n", rank );
	
	/* Read input */
	dictionary = Dictionary_New();
	
	/* Build the context */
	abstractContext = _AbstractContext_New( 
		sizeof(AbstractContext), 
		"TestContext", 
		MyDelete, 
		MyPrint, 
		NULL,
		NULL, 
		NULL, 
		_AbstractContext_Build, 
		_AbstractContext_Initialise, 
		_AbstractContext_Execute, 
		_AbstractContext_Destroy, 
		"context", 
		True, 
		MySetDt, 
		0, 
		10, 
		CommWorld, 
		dictionary );

	/* add hooks to existing entry points */
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Build, MyBuild );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Solve, MySolve );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Dt, MyDt );

	if( rank == procToWatch ) {
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->_size: %lu\n", 
			abstractContext->entryPoint_Register->_size );
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->count: %u\n", 
			abstractContext->entryPoint_Register->count );
	}
	
	ContextEP_Append( abstractContext, AbstractContext_EP_Solve, MySolve2 );
	ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions2 ); 

	if( rank == procToWatch ) {
		stream = Journal_Register( InfoStream_Type, AbstractContext_Type );
		AbstractContext_PrintConcise( abstractContext, stream );
		
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->_size: %lu\n", 
			abstractContext->entryPoint_Register->_size );
		Journal_Printf( 
			(void*)stream, 
			"abstractContext->entryPointList->count: %u\n", 
			abstractContext->entryPoint_Register->count );
	}

	/* Run the context */
	if( rank == procToWatch ) {
		Stg_Component_Build( abstractContext, 0 /* dummy */, False );
		Stg_Component_Initialise( abstractContext, 0 /* dummy */, False );
		Stg_Component_Execute( abstractContext, 0 /* dummy */, False );
		Stg_Component_Destroy( abstractContext, 0 /* dummy */, False );
	}
	
	/* Stg_Class_Delete stuff */
	Stg_Class_Delete( abstractContext );
	Stg_Class_Delete( dictionary );
	
	BaseContext_Finalise();
	BaseExtensibility_Finalise();
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();
	BaseFoundation_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}