void _Trubitsyn2006_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
   Trubitsyn2006*     self = (Trubitsyn2006*)analyticSolution;
   ConditionFunction* condFunc;
   char*              viscosityType;
   FeVariable*        velocityField;
   FeVariable*        pressureField;
   double             Ra;
   double             T0;
   int                wavenumberX;
   int                wavenumberY;
   
   velocityField = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"VelocityField",
      FeVariable, True, data);

   pressureField = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"PressureField",
      FeVariable, True, data);

   /* Add temperature initial condition */
   condFunc = ConditionFunction_New(
      Trubitsyn2006_TemperatureIC,
      (Name)"Trubitsyn2006_TemperatureIC", NULL );
   ConditionFunction_Register_Add( condFunc_Register, condFunc );

   /* Add pressure initial condition */
   condFunc = ConditionFunction_New( Trubitsyn2006_PressureIC, (Name)"Trubitsyn2006_PressureIC", NULL );
   ConditionFunction_Register_Add( condFunc_Register, condFunc );
   
   Ra = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"Ra", 0.0 );
   T0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"T0", 0.0 );
   wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
   wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );

   /* Setup Viscosity Functions */
   viscosityType = Stg_ComponentFactory_GetRootDictString( cf, (Dictionary_Entry_Key)"ViscosityType",
      "Isoviscous" );

   _Trubitsyn2006_Init(
      self,
      velocityField,
      pressureField,
      Ra,
      T0,
      wavenumberX,
      wavenumberY,
      viscosityType );
}
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 _HomogeneousEssentialBCs_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
	HomogeneousEssentialBCs* self = (HomogeneousEssentialBCs*)analyticSolution;
	AbstractContext*       context;
	ConditionFunction*     condFunc;

	_AnalyticSolution_AssignFromXML( self, cf, data );

	self->temperatureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"TemperatureField", FeVariable, True, data  ); 
	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->temperatureField, HomogeneousEssentialBCs_TemperatureFunction );

	self->angle = StGermain_DegreeToRadian (Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"VelocitySkewAngle", 45.0 )  );

	/* Create Condition Functions */
	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
	condFunc = ConditionFunction_New( HomogeneousEssentialBCs_Velocity_SkewToMesh, (Name)"Velocity_SkewToMesh", NULL  );
	ConditionFunction_Register_Add( context->condFunc_Register, condFunc );
	condFunc = ConditionFunction_New( HomogeneousEssentialBCs_TemperatureBC, (Name)"Temperature_StepFunction", NULL  );
	ConditionFunction_Register_Add( context->condFunc_Register, condFunc );
}
Example #4
0
void _SnacCondFunc_Construct( void* component, Stg_ComponentFactory* cf, void* data ) {
	Snac_Context*	context;
	context = (Snac_Context*)Stg_ComponentFactory_ConstructByName( cf, "context", Snac_Context, True, data ); 
	Journal_Printf( context->snacInfo, "In: %s\n", __func__ );
	
	ConditionFunction_Register_Add(
			context->condFunc_Register,
			ConditionFunction_New(_SnacCondFunc_AssignPhaseID,"SnacCF_AssignPhaseID" ) );
	ConditionFunction_Register_Add(
			context->condFunc_Register,
			ConditionFunction_New(_SnacCondFunc_DeadSea,"SnacCF_DeadSea" ) );
	ConditionFunction_Register_Add(
			context->condFunc_Register,
			ConditionFunction_New( _SnacCondFunc_MaxwellBenchmark,"SnacCF_MaxwellBenchmark" ) );
	ConditionFunction_Register_Add(
			context->condFunc_Register,
			ConditionFunction_New( _SnacCondFunc_ObliqueRift,"SnacCF_ObliqueRift" ) );
	ConditionFunction_Register_Add(
			context->condFunc_Register,
			ConditionFunction_New( _SnacCondFunc_Orogeny,"SnacCF_Orogeny" ) );
}
void _FieldVariableConditionFunctionSecondCopy_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
	FieldVariableConditionFunctionSecondCopy* self = (FieldVariableConditionFunctionSecondCopy*)component;
	Dictionary*		pluginDict	= Codelet_GetPluginDictionary( component, cf->rootDict );

	/** field variable which we will interrogate to determine values */
   self->fieldVariable = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"FieldVariable", FieldVariable, True, data );
	/** target fevariable */
   self->targetfeVariable = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"TargetFeVariable", FeVariable, True, data  );
	self->failTolerance = Dictionary_GetDouble_WithDefault( pluginDict, (Dictionary_Entry_Key)"FailureTolerance" , 0.001 );
	
	ConditionFunction_Register_Add( condFunc_Register, ConditionFunction_New( FieldVariableConditionFunctionSecondCopy_getVal, (Name)self->type, NULL ) );

}
void _lecode_tools_Isostasy_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )
{
   lecode_tools_Isostasy* self = (lecode_tools_Isostasy*)component;
   ConditionFunction *cond_func;
   Dictionary* pluginDict = Codelet_GetPluginDictionary( component, cf->rootDict );

   lecode_tools_Isostasy_self = self;

   self->context = (AbstractContext*)Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"Context"  ), UnderworldContext, True, data );
   self->ctx = self->context;
   self->mesh = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"mesh"  ), FeMesh, True, data );
   self->swarm = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"swarm"  ), IntegrationPointsSwarm, True, data );
   /*
     self->heightField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"HeightField"  ), FeVariable, True, data );
   */
   self->surfaceIdx = Stg_ComponentFactory_PluginGetInt( cf, self, "SurfaceIndex", -1 );
   self->vertAxis = Stg_ComponentFactory_PluginGetInt( cf, self, "VerticalAxis", 1 );
   if( self->vertAxis == 1 )
      self->zontalAxis = 2;
   else if( self->vertAxis == 2 )
      self->zontalAxis = 1;
   else
      Journal_Firewall( NULL,
       Journal_MyStream( Error_Type, self ),
       "\n\nError in %s for %s - Isostasy plugin requires 'VerticalAxis' to be '1' (standard UW) or '2'.",
       __func__,
       self->type );

   self->avg = Stg_ComponentFactory_PluginGetBool( cf, self, "UseAverage", True );
   self->vel_field = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"velocityField"  ), FeVariable, True, data );
   self->buoyancy = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"buoyancy"  ), BuoyancyForceTerm, False, data );
   self->rho_zero_mat = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"rhoZeroMaterial"  ), Material, True, data );
   self->sle = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"sle"  ), SystemLinearEquations, True, data );
   self->thermalSLE = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"thermalSLE"  ), SystemLinearEquations, False, data );
   if (self->thermalSLE)
   {
      self->tempField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"temperatureField"  ), FeVariable, True, data );
      self->tempDotField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"temperatureDotField"  ), FeVariable, True, data );
   }
   self->maxIts = Stg_ComponentFactory_PluginGetInt( cf, self, "MaxIterations", -1 );

   SystemLinearEquations_SetToNonLinear(self->sle);
   SystemLinearEquations_AddNonLinearEP(self->sle, lecode_tools_Isostasy_Type, lecode_tools_Isostasy_NonLinearEP);

   cond_func = ConditionFunction_New( (ConditionFunction_ApplyFunc*)lecode_tools_Isostasy_SetBC, (Name)"lecode_tools_Isostasy", NULL );
   ConditionFunction_Register_Add( condFunc_Register, cond_func);

   /** check if PPCing */
   if(!self->buoyancy){
      self->ppcManager = NULL;
      self->ppcManager = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Manager", PpcManager, False, data );
      if( !self->ppcManager  )
         self->ppcManager = Stg_ComponentFactory_ConstructByName( cf, (Name)"default_ppcManager", PpcManager, False, data  );
         if( !self->ppcManager )
            Journal_Firewall( NULL,
                 Journal_MyStream( Error_Type, self ),
                 "\n\nError in %s for %s - Neither a BuoyancyForceTerm or Ppc manager was found .\nIsostasy plugin requires one OR the other to operate.\n\n\n",
                 __func__,
                 self->type );
         if( self->thermalSLE )
            Journal_Firewall( NULL,
                 Journal_MyStream( Error_Type, self ),
                 "\n\nError in %s for %s - Ppc not compatible with thermalSLE option.\n\n\n",
                 __func__,
                 self->type );

      self->densityID = PpcManager_GetPpcFromDict( self->ppcManager, cf, self->name, (Dictionary_Entry_Key)"DensityLabel", "DensityLabel" );

   }

}
void WallVCSuite_TestWallVC( WallVCSuiteData* data ) {
   unsigned                    nDomains;
   unsigned                    nDims = 3;
   unsigned                    meshSize[3] = {3, 3, 3};
   int                         procToWatch;
   double                      minCrds[3] = {0.0, 0.0, 0.0};
   double                      maxCrds[3] = {1.0, 1.0, 1.0};
   char*                       vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right",
                                          "WallVC_Top", "WallVC_Bottom"};
   char*                       vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName",
                                          "WallVC_TopName", "WallVC_BottomName"};
   char*                       varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
   char                        input_file[PCU_PATH_MAX];
   char                        expected_file[PCU_PATH_MAX];
   Mesh*                       mesh;
   Variable_Register*          variable_Register;
   ConditionFunction*          quadCF;
   ConditionFunction*          expCF;
   ConditionFunction_Register* conFunc_Register;
   ExtensionManager_Register*  extensionMgr_Register;
   Dictionary*                 dictionary;
   Dictionary*                 sources;
   Stream*                     stream;
   XML_IO_Handler*             io_handler;
   Variable*                   var[7];
   double*                     array[7];
   VariableCondition*          vc; 
   Index                       i;

   procToWatch = data->nProcs >=2 ? 1 : 0;

   io_handler = XML_IO_Handler_New();

    stream = Journal_Register( Info_Type, (Name)"WallVCStream"  );
   Stream_RedirectFile( stream, "testWallVC.dat" );

   dictionary = Dictionary_New();
   sources = Dictionary_New();
   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );

   /* Input file */
   pcu_filename_input( "wallVC.xml", input_file );
   IO_Handler_ReadAllFromFile( io_handler, input_file, dictionary, sources );
   fflush( stdout );

   extensionMgr_Register = ExtensionManager_Register_New(); 

   /* Create a mesh. */
   mesh = (Mesh*) WallVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );

   /* Create CF stuff */
   quadCF = ConditionFunction_New( WallVCSuite_quadratic, (Name)"quadratic", NULL );
   expCF = ConditionFunction_New( WallVCSuite_exponential, (Name)"exponential", NULL);
   conFunc_Register = ConditionFunction_Register_New( );
   ConditionFunction_Register_Add(conFunc_Register, quadCF);
   ConditionFunction_Register_Add(conFunc_Register, expCF);

   /* Create variable register */
   variable_Register = Variable_Register_New();

   /* Create variables */
   for (i = 0; i < 6; i++) {
      array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
      Variable_Register_Add(variable_Register, var[i]);
   }
   array[6] = Memory_Alloc_Array( double, nDomains * 5, "array[6]" );
   var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
   Variable_Register_Add(variable_Register, var[6]);
   Variable_Register_BuildAll(variable_Register);

   for (i = 0; i < 6; i++) {
      Index j, k;

      vc = (VariableCondition*) WallVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
      Stg_Component_Build( vc, 0, False );

      for (j = 0; j < 6; j++)
         memset(array[j], 0, sizeof(double)* nDomains );
      memset(array[6], 0, sizeof(double)* nDomains * 5);
      VariableCondition_Apply(vc, NULL);

      if (data->rank == procToWatch) {
         Journal_Printf( stream,"Testing for %s\n", vcKey[i]);
         for (j = 0; j < 6; j++) {
            Journal_Printf( stream,"\nvar[%u]: %.2lf", j, array[j][0]);
            for (k = 1; k < nDomains; k++)
               Journal_Printf( stream,", %.2lf", array[j][k]);
         }

         Journal_Printf( stream,"\nvar[6]: %.2lf", array[6][0]);
         for (j = 1; j < nDomains*5; j++)
            Journal_Printf( stream,", %.2lf", array[6][j]);
         Journal_Printf( stream,"\n\n");

         for (j = 0; j < 7; j++) {
            for (k = 0; k < nDomains; k++)
               Journal_Printf( stream,"%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
            Journal_Printf( stream,"\n");
         } Journal_Printf( stream,"\n");

         for (j = 0; j < 7; j++) {
            for (k = 0; k < nDomains; k++) {
               VariableCondition_ValueIndex  valIndex;
               valIndex = VariableCondition_GetValueIndex(vc, k, j);
               if (valIndex != (unsigned)-1)
                  Journal_Printf( stream,"%03u ", valIndex);
               else
                  Journal_Printf( stream,"XXX ");
            } Journal_Printf( stream,"\n");
         } Journal_Printf( stream,"\n");
      }
      Stg_Class_Delete(vc);
   }

   if (data->rank == procToWatch) {
      pcu_filename_expected( "testWallVC.expected", expected_file );
      pcu_check_fileEq( "testWallVC.dat", expected_file );
      remove( "testWallVC.dat" );
   }

   Stg_Class_Delete(variable_Register);
   for (i = 0; i < 7; i++) {
      Stg_Class_Delete(var[i]);
      if (array[i]) Memory_Free(array[i]);
   }
   Stg_Class_Delete(extensionMgr_Register);
   Stg_Class_Delete(io_handler);
   Stg_Class_Delete(conFunc_Register);
   Stg_Class_Delete(quadCF);
   Stg_Class_Delete(expCF);
   Stg_Class_Delete(dictionary);
   Stg_Class_Delete(sources);
   FreeObject( mesh );
}
Example #8
0
int main(int argc, char *argv[])
{
	MPI_Comm		CommWorld;
	int		rank;
	int		procCount;
	int		procToWatch;
	Stream*		stream;
	
	Dictionary*		dictionary;
	XML_IO_Handler*		io_handler;
	
	Topology*       nTopology;
	ElementLayout*	eLayout;
	NodeLayout*	nLayout;
	MeshDecomp*	decomp;
	MeshLayout*	layout;
	Mesh*		mesh;
	
	Variable*			var[7];
	Variable_Register*		variable_Register;
	WallVC*				vc;
	ConditionFunction*		quadCF;
	ConditionFunction*		expCF;
	ConditionFunction_Register*	conFunc_Register;

	ExtensionManager_Register*		extensionMgr_Register;
	
	double*		array[7];
	char*		vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right",
				"WallVC_Top", "WallVC_Bottom"};
	char*		vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName",
				"WallVC_TopName", "WallVC_BottomName"};
	char*		varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
	
	Index	i;

	
	/* Initialise MPI, get world info */
	MPI_Init(&argc, &argv);
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size(CommWorld, &procCount);
	MPI_Comm_rank(CommWorld, &rank);
	
	Base_Init( &argc, &argv );
	
	DiscretisationGeometry_Init( &argc, &argv );
	DiscretisationShape_Init( &argc, &argv );
	DiscretisationMesh_Init( &argc, &argv );
	DiscretisationUtils_Init( &argc, &argv );
	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */

	io_handler = XML_IO_Handler_New();

	stream = Journal_Register (Info_Type, "myStream");
	
	procToWatch = argc >= 2 ? atoi(argv[1]) : 0;
	
	dictionary = Dictionary_New();
	IO_Handler_ReadAllFromFile(io_handler, "data/wallVC.xml", dictionary);
	fflush(stdout);
	MPI_Barrier(MPI_COMM_WORLD);
	Dictionary_Add(dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt(rank));
	Dictionary_Add(dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt(procCount));
	Dictionary_Add(dictionary, "meshSizeI", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "meshSizeJ", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "meshSizeK", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "allowUnbalancing", Dictionary_Entry_Value_FromBool(True));

	extensionMgr_Register = ExtensionManager_Register_New();	
	
	nTopology = (Topology*)IJK6Topology_New( "IJK6Topology", dictionary );
	eLayout = (ElementLayout*)ParallelPipedHexaEL_New( "PPHexaEL", 3, dictionary );
	nLayout = (NodeLayout*)CornerNL_New( "CornerNL", dictionary, eLayout, nTopology );
	decomp = (MeshDecomp*)HexaMD_New( "HexaMD", dictionary, MPI_COMM_WORLD, eLayout, nLayout );
	layout = MeshLayout_New( "MeshLayout", eLayout, nLayout, decomp );
	mesh = Mesh_New( "Mesh", layout, 0, 0, extensionMgr_Register, dictionary );
	
	/* Create CF stuff */
	quadCF = ConditionFunction_New(quadratic, "quadratic");
	expCF = ConditionFunction_New(exponential, "exponential");
	conFunc_Register = ConditionFunction_Register_New();
	ConditionFunction_Register_Add(conFunc_Register, quadCF);
	ConditionFunction_Register_Add(conFunc_Register, expCF);
	
	/* Create variable register */
	variable_Register = Variable_Register_New();
	
	/* Create variables */
	for (i = 0; i < 6; i++) {
		array[i] = Memory_Alloc_Array( double, decomp->nodeLocalCount, "array[i]" );
		var[i] = Variable_NewScalar( varName[i], Variable_DataType_Double, &decomp->nodeLocalCount, (void**)&array[i], 0 ); 
		Variable_Register_Add(variable_Register, var[i]);
	}
	array[6] = Memory_Alloc_Array( double, decomp->nodeLocalCount * 5, "array[6]" );
	var[6] = Variable_NewVector( varName[6], Variable_DataType_Double, 5, &decomp->nodeLocalCount, (void**)&array[6], 0 );
	Variable_Register_Add(variable_Register, var[6]);
	Variable_Register_BuildAll(variable_Register);
	
	/* Create WallVC */
	for (i = 0; i < 6; i++)
	{
		Index	j, k;
		
		vc = WallVC_New( vcKeyName[i], vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
		Build( vc, 0, False );
		
		for (j = 0; j < 6; j++)
			memset(array[j], 0, sizeof(double)* decomp->nodeLocalCount );
		memset(array[6], 0, sizeof(double)* decomp->nodeLocalCount * 5);
		VariableCondition_Apply(vc, NULL);
	
		if (rank == procToWatch)
		{
			printf("Testing for %s\n", vcKey[i]);
			Print(vc, stream);
			printf("\n");
			for (j = 0; j < 6; j++)
			{
				printf("\nvar[%u]: %.2lf", j, array[j][0]);
				for (k = 1; k < decomp->nodeLocalCount; k++)
					printf(", %.2lf", array[j][k]);
			}
			printf("\nvar[6]: %.2lf", array[6][0]);
			for (j = 1; j < decomp->nodeLocalCount*5; j++)
				printf(", %.2lf", array[6][j]);
			printf("\n\n");
			
			for (j = 0; j < 7; j++)
			{
				for (k = 0; k < decomp->nodeLocalCount; k++)
					printf("%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
				printf("\n");
			}
			printf("\n");
			
			for (j = 0; j < 7; j++)
			{
				for (k = 0; k < decomp->nodeLocalCount; k++)
				{
					VariableCondition_ValueIndex	valIndex;
					
					valIndex = VariableCondition_GetValueIndex(vc, k, j);
					if (valIndex != (unsigned)-1)
						printf("%03u ", valIndex);
					else
						printf("XXX ");
				}
				printf("\n");
			}
			printf("\n");
		}
		
		Stg_Class_Delete(vc);
	}
		
	Stg_Class_Delete(variable_Register);
	for (i = 0; i < 7; i++)
	{
		Stg_Class_Delete(var[i]);
		if (array[i]) Memory_Free(array[i]);
	}
	Stg_Class_Delete(conFunc_Register);
	Stg_Class_Delete(quadCF);
	Stg_Class_Delete(expCF);
	Stg_Class_Delete(layout);
	Stg_Class_Delete(decomp);
	Stg_Class_Delete(nLayout);
	Stg_Class_Delete(eLayout);
	Stg_Class_Delete( nTopology );
	Stg_Class_Delete(dictionary);
	
	DiscretisationUtils_Finalise();
	DiscretisationMesh_Finalise();
	DiscretisationShape_Finalise();
	DiscretisationGeometry_Finalise();
	
	Base_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Example #9
0
void _SnacRemesher_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacRemesher_Context*			contextExt = ExtensionManager_Get(
							context->extensionMgr,
							context,
							SnacRemesher_ContextHandle );
	Mesh*					mesh = context->mesh;
	SnacRemesher_Mesh*			meshExt = ExtensionManager_Get(
							context->meshExtensionMgr,
							mesh,
							SnacRemesher_MeshHandle );
	char*					conditionStr;
	Dictionary_Entry_Value*			conditionCriterion;
	Dictionary* 				meshDict;
	Stream*					error = Journal_Register( Error_Type, "Remesher" );
	char					tmpBuf[PATH_MAX];

	Journal_Printf( context->debug, "In: %s\n", __func__ );
	
	contextExt->debugIC = Journal_Register( Debug_Type, "Remesher-ICs" );
	contextExt->debugCoords = Journal_Register( Debug_Type, "Remesher-Coords" );
	contextExt->debugNodes = Journal_Register( Debug_Type, "Remesher-Nodes" );
	contextExt->debugElements = Journal_Register( Debug_Type, "Remesher-Elements" );
	contextExt->debugSync = Journal_Register( Debug_Type, "Remesher-Sync" );
	
	/* Additional tables required over the nodeElementTbl already required by core Snac */
	Mesh_ActivateNodeNeighbourTbl( mesh );
	Mesh_ActivateElementNeighbourTbl( mesh );
	
	/* Work out condition to remesh on */
	if( !Dictionary_Get( context->dictionary, CONDITION_STR ) ) {
		Journal_Printf( 
			error,
			"Warning: No \"%s\" entry in dictionary... will default to \"%s\"\n", 
			CONDITION_STR,
			OFF_STR );
	}
	
	conditionStr = Dictionary_Entry_Value_AsString( 
		Dictionary_GetDefault( context->dictionary, CONDITION_STR, Dictionary_Entry_Value_FromString( OFF_STR ) ) );
	
	contextExt->OnTimeStep = 0;
	contextExt->onMinLengthScale = 0;
	if( !strcmp( conditionStr, OFF_STR ) ) {
		contextExt->condition = SnacRemesher_Off;
		Journal_Printf( context->snacInfo, "Remesher is off\n" );
	}
	else if( !strcmp( conditionStr, ONTIMESTEP_STR ) ) {
		contextExt->condition = SnacRemesher_OnTimeStep;
		conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated based on timeStep\n" );
		
		if( conditionCriterion ) {
			contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remeshing every %u timeSteps\n", contextExt->OnTimeStep );
	}
	else if( !strcmp( conditionStr, ONMINLENGTHSCALE_STR ) ) {
		contextExt->condition = SnacRemesher_OnMinLengthScale;
		conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated by minLengthScale\n" );
		
		if( conditionCriterion ) {
			contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remesh when minLengthScale < %g\n", contextExt->onMinLengthScale );
	}
	else if( !strcmp( conditionStr, ONBOTHTIMESTEPLENGTH_STR ) ) {
		contextExt->condition = SnacRemesher_OnBothTimeStepLength;
		conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated by both timeStep and minLengthScale\n" );
		
		if( conditionCriterion ) {
			contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion );
			conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR );
			contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remesh every %u timeSteps or wheen minLengthScale < %g\n", contextExt->OnTimeStep, contextExt->onMinLengthScale );
	}
	else {
		contextExt->condition = SnacRemesher_Off;
		Journal_Printf( context->snacInfo, "Remesher is defaulting to off\n" );
		Journal_Printf( error, "Provided remesh condition \"%s\" unrecognised\n", conditionStr );
	}
	
	
	/* Work out the mesh type */
	meshDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( context->dictionary, MESH_STR ) );
	if( meshDict ) {
		char* 					meshTypeStr;
		
		if( !Dictionary_Get( meshDict, MESHTYPE_STR ) ) {
			Journal_Printf( 
				error,
				"Warning: No \"%s\" entry in \"%s\"... will default to \"%s\"\n", 
				MESHTYPE_STR, 
				MESH_STR, 
				CARTESIAN_STR );
		}
		
		meshTypeStr = Dictionary_Entry_Value_AsString( 
			Dictionary_GetDefault( meshDict, MESHTYPE_STR, Dictionary_Entry_Value_FromString( CARTESIAN_STR ) ) );
		
		if( !strcmp( meshTypeStr, SPHERICAL_STR ) ) {
			meshExt->meshType = SnacRemesher_Spherical;
			Journal_Printf( context->snacInfo, "Remesher knows mesh as a spherical mesh\n" );
		}
		else if( !strcmp( meshTypeStr, CARTESIAN_STR ) ) {
			meshExt->meshType = SnacRemesher_Cartesian;
			Journal_Printf( context->snacInfo, "Remesher knows mesh as a cartesian mesh\n" );
		}
		else {
			meshExt->meshType = SnacRemesher_Cartesian;
			Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" );
			Journal_Printf( error, "Provided mesh type \"%s\" unrecognised!\n", meshTypeStr );
		}
	}
	else {
		meshExt->meshType = SnacRemesher_Cartesian;
		Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" );
		Journal_Printf( error, "No \"%s\" entry in dictionary!\n", MESH_STR );
	}
	/* Decide whether to restore the bottom surface */
	contextExt->bottomRestore = 0;
	if( !strcmp( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( context->dictionary, "bottomRestore", Dictionary_Entry_Value_FromString( OFF_STR ) ) ), ON_STR) )
		contextExt->bottomRestore = 1;


	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_TestCondFunc, "SnacRemesher_TestCondFunc" ) );
	
	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_XFunc, "SnacRemesher_XFunc" ) );
	
	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_YFunc, "SnacRemesher_YFunc" ) );
	
	/* Obtain the keys for the our new entry points... having the keys saves doing a string compare at run time */
	contextExt->recoverNodeK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_RecoverNode );
	contextExt->interpolateNodeK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_InterpolateNode );
	contextExt->interpolateElementK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_InterpolateElement );

	/* Prepare the dump file */
	if( context->rank == 0) {
		sprintf( tmpBuf, "%s/remeshInfo.%u", context->outputPath, context->rank );
		if( (contextExt->remesherOut = fopen( tmpBuf, "w+" )) == NULL ) {
			assert( contextExt->remesherOut /* failed to open file for writing */ );
		}
	}
	/* initialize remeshing counter */
	contextExt->remeshingCount = 0;
}
Example #10
0
void _SnacTemperature_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacTemperature_Context*		contextExt = ExtensionManager_Get(
							context->extensionMgr,
							context,
							SnacTemperature_ContextHandle );
	Snac_Node				tmpNode;
	SnacTemperature_Node*			tmpNodeExt = ExtensionManager_Get(
							context->mesh->nodeExtensionMgr,
							&tmpNode,
							SnacTemperature_NodeHandle );
	Dictionary*				temperatureBCsDict;
	char					tmpBuf[PATH_MAX];
	
	/* Because temperature is not an array by itself, we must the "complex" constructor for Variable... the info needs to be
	 * wrapped this generic way... */
	Index					temperatureOffsetCount = 1;
	SizeT					temperatureOffsets[] = { /*GetOffsetOfMember( *tmpNodeExt, temperature ) };*/
		(SizeT)((char*)&tmpNodeExt->temperature - (char*)&tmpNode) };
	Variable_DataType			temperatureDataTypes[] = { Variable_DataType_Double };
	Index					temperatureDataTypeCounts[] = { 1 };
	
		
	#if DEBUG
		printf( "In %s()\n", __func__ );
	#endif

	/* Create the StGermain variable temperature, which is stored on a node extension */
	Variable_New( 
		"temperature", 
		temperatureOffsetCount, 
		temperatureOffsets, 
		temperatureDataTypes, 
		temperatureDataTypeCounts, 
		0, 
		&ExtensionManager_GetFinalSize( context->mesh->nodeExtensionMgr ),
		&context->mesh->layout->decomp->nodeDomainCount,
		(void**)&context->mesh->node,
		context->variable_Register );

	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Top2BottomSweep, "SnacTemperature_Top2BottomSweep" ) );
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Top2BottomSweep_Spherical, "SnacTemperature_Top2BottomSweep_Spherical" ) );
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Citcom_Compatible, "SnacTemperature_Citcom_Compatible" ) );

	/* Temperature variables */
	contextExt->topTemp = Dictionary_Entry_Value_AsDouble(
		Dictionary_GetDefault( context->dictionary, "topTemp", Dictionary_Entry_Value_FromDouble( 0.0f ) ) );

	contextExt->bottomTemp = Dictionary_Entry_Value_AsDouble(
		Dictionary_GetDefault( context->dictionary, "bottomTemp", Dictionary_Entry_Value_FromDouble( 1300.0f ) ) );

	/* Build the temperature IC and BC managers */
	temperatureBCsDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( context->dictionary, "temperatureBCs" ) );
	contextExt->temperatureBCs = CompositeVC_New("tempBC",
		context->variable_Register,
		context->condFunc_Register,
		temperatureBCsDict,
		context->mesh );

	/* Prepare the dump and checkpoint file */
	sprintf( tmpBuf, "%s/temperature.%u", context->outputPath, context->rank );
	if( (contextExt->temperatureOut = fopen( tmpBuf, "w+" )) == NULL ) {
		assert( contextExt->temperatureOut /* failed to open file for writing */ );
		abort();
	}
	sprintf( tmpBuf, "%s/temperatureCP.%u", context->outputPath, context->rank );
	if( (contextExt->temperatureCheckpoint = fopen( tmpBuf, "w+" )) == NULL ) {
		assert( contextExt->temperatureCheckpoint /* failed to open file for writing */ );
		abort();
	}
}