void Variable_SetValueFromDictionary( void* _variable, Index index, Dictionary* dictionary ) {
	Variable*          variable = (Variable*)_variable;

	Variable_Update( variable );
	
	/* Assign variable from dictionary according to data type */
	switch (variable->dataTypes[0]) {
		case Variable_DataType_Char:
			Variable_SetValueChar(  variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
			break;
		case Variable_DataType_Short:
			Variable_SetValueShort( variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
			break;
		case Variable_DataType_Int:
			Variable_SetValueInt( variable, index, Dictionary_GetInt( dictionary, (Dictionary_Entry_Key)variable->name ) );
			break;
		case Variable_DataType_Float:
			Variable_SetValueFloat(  variable, index, Dictionary_GetDouble( dictionary, variable->name ));
			break;
		case Variable_DataType_Double:
			Variable_SetValueDouble( variable, index, Dictionary_GetDouble( dictionary, variable->name ));
			break;
		default: {
			Journal_Printf( 
				Journal_MyStream( Error_Type, variable ), 
				"In func %s: Unable to set value of %s from dictionary.", 
				__func__, 
				variable->name );
		}
	}
}
Ejemplo n.º 2
0
void _SLE_Solver_Init( SLE_Solver* self, Bool useStatSolve, int statReps ) {
	self->isConstructed = True;
	self->extensionManager = ExtensionManager_New_OfExistingObject( self->name, self );
	
	self->debug         = Stream_RegisterChild( StgFEM_SLE_SystemSetup_Debug, self->type );
	self->info          = Journal_MyStream( Info_Type, self );
	self->maxIterations = 0;
	self->hasSolved = False;

	self->previoustimestep = 0;
	self->currenttimestep = 0;
	self->nonlinearitsinitialtime = 0; 
	self->nonlinearitsendtime = 0; 
	self->totalnonlinearitstime = 0; 
	self->totalnumnonlinearits = 0; 
	self->avgtimenonlinearits = 0; 	
	self->inneritsinitialtime = 0; 
	self->outeritsinitialtime = 0; 
	self->inneritsendtime = 0; 
	self->outeritsendtime = 0; 
	self->totalinneritstime = 0; 
	self->totalouteritstime = 0; 
	self->totalnuminnerits = 0; 
	self->totalnumouterits = 0; 
	self->avgnuminnerits = 0; 
	self->avgnumouterits = 0; 
	self->avgtimeinnerits = 0; 
	self->avgtimeouterits = 0;
	
	self->useStatSolve = useStatSolve;
	self->nStatReps     = statReps;
}
Ejemplo n.º 3
0
void _GeneralSwarm_UpdateHook( void* timeIntegrator, void* swarm )
{
   GeneralSwarm* self = (GeneralSwarm*)swarm;
   Index                cell;
   Index                point_I;
   GlobalParticle*      particle;

   /* Need to check for escaped particles before the next block. */
   if ( self->escapedRoutine )
   {
      Stg_Component_Execute( self->escapedRoutine, self, True );
   }

   /* Check that particles have not exited the box after advection */
   if ( self->swarmAdvector  )
   {
      for ( point_I = 0; point_I < self->particleLocalCount; ++point_I )
      {
         particle = (GlobalParticle*)Swarm_ParticleAt( self, point_I );
         cell = particle->owningCell;
         Journal_Firewall(
            cell < self->cellLocalCount,
            Journal_MyStream( Error_Type, self ),
            "In func %s: GlobalParticle '%d' outside element. Coord = {%g, %g, %g}\n",
            __func__,
            point_I,
            particle->coord[ I_AXIS ],
            particle->coord[ J_AXIS ],
            particle->coord[ K_AXIS ] );
      }
   }

}
Ejemplo n.º 4
0
void _FileParticleLayout_Init( void* particleLayout, Name filename )
{
	FileParticleLayout* self = (FileParticleLayout*) particleLayout;

	self->filename = StG_Strdup( filename );
	self->file        = NULL;
	self->errorStream = Journal_MyStream( Error_Type, self );
	_GlobalParticleLayout_Init( self, GlobalCoordSystem, False, 0, 0.0 );
}
void _OneToOneMapper_Init( void* mapper, MaterialPointsSwarm* materialSwarm ) {
	OneToOneMapper* self = (OneToOneMapper*)mapper;
	
	self->errorStream = Journal_MyStream( Error_Type, self );
	self->materialSwarm = materialSwarm;

	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
	self->materialRefHandle = ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, (Name)materialSwarm->name, sizeof(MaterialPointRef)  );
	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
}
void _TimeIntegrator_ExecuteRK2Simultaneous( void* timeIntegrator, void* data ) {
	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
	AbstractContext*	context = (AbstractContext*) data;
	Index					integrand_I;   
	Index					integrandCount = TimeIntegrator_GetCount( self );
	double				dt = self->dt;
	TimeIntegrand*	integrand;
	Variable**			originalVariableList;

    assert(0); /* this shit be broken */
	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );

	Journal_Firewall( 
		False,
		Journal_MyStream( Error_Type, self ),
		"Error in %s '%s' - This function is temporarily unavailable \n"
		"Please only use non-simultaneous update or only first order update.\n", 
		self->type, self->name );

	/* Set Time */
	TimeIntegrator_SetTime( self, context->currentTime );

	originalVariableList = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" );
	
	TimeIntegrator_Setup( self );
	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
		Journal_RPrintf(self->info,"\t2nd order (simultaneous): %s\n", integrand->name);
		
		/* Store Original */
		originalVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "Original", True );

		/* Predictor Step */
		TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt );
	}
	TimeIntegrator_Finalise( self );
	
	/* Set Time */
	TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt );

	TimeIntegrator_Setup( self );
	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
		integrand = TimeIntegrator_GetByIndex( self, integrand_I );

		/* Corrector Step */
		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt );

		/* Free Original */
		Stg_Class_Delete( originalVariableList[ integrand_I ] );
	}
	TimeIntegrator_Finalise( self );
	Memory_Free( originalVariableList );
}
void _MaterialPointsSwarm_Initialise( void* swarm, void* data ) {
	MaterialPointsSwarm*	self 	= (MaterialPointsSwarm*) swarm;
	AbstractContext* 	context = (AbstractContext*)self->context;
	Index            	var_I	= 0;
	Particle_Index          lParticle_I=0;
	MaterialPoint*		matPoint=NULL;

	_GeneralSwarm_Initialise( self, data );

	if( self->material       != NULL) Stg_Component_Initialise( self->material,       data , False );

	/* Now setup the material properties */
   if(  (False == context->loadFromCheckPoint) || False == (context->loadSwarmsFromCheckpoint) ) {

      /* Beforehand, set each particle to have UNDEFINED_MATERIAL */
      for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
         matPoint = (MaterialPoint*)Swarm_ParticleAt( self, lParticle_I );
         matPoint->materialIndex = UNDEFINED_MATERIAL;
      }
		if( self->material == NULL ) {
			/* Do it by the layout of all known materials */
			Materials_Register_SetupSwarm( self->materials_Register, self );
		}
		else {
			Material_Layout( self->material, self );
			Materials_Register_AssignParticleProperties( 
					self->materials_Register, 
					self, 
					self->swarmVariable_Register->variable_Register );
		}
	}

   if( self->overrideMaterialCheck == False ) {
      /* Check to ensure all particles have a valid material  */
      for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
         matPoint = (MaterialPoint*)Swarm_ParticleAt( self, lParticle_I );
         Journal_Firewall( (matPoint->materialIndex != UNDEFINED_MATERIAL), Journal_MyStream( Error_Type, self ),
               "Error in function %s for swarm '%s'. Material point at (%.5g, %.5g, %.5g), has no material assigned to it.\n"
               "This is most likely because the material geometries don't cover the entire domain - check material/geometry definitions\n\n"
               "To check: visualise the material index field initialisation by running your model with the commandline options\n"
               "\t\'--maxTimeSteps=-1 --components.%s.overrideMaterialCheck=True\'\n", __func__, self->name, matPoint->coord[0], matPoint->coord[1], matPoint->coord[2], self->name);  
      }
   }
}
void _IntegrationPointsSwarm_AssignFromXML( void* integrationPoints, Stg_ComponentFactory* cf, void* data ) {
   IntegrationPointsSwarm* self = (IntegrationPointsSwarm*) integrationPoints;
   FeMesh*                 mesh;
   TimeIntegrator*         timeIntegrator;
   WeightsCalculator*      weights;
   IntegrationPointMapper* mapper;
   Materials_Register*     materials_Register;
   Bool                    recalculateWeights;
   PICelleratorContext*    context;

   /* This will also call _Swarm_Init */
   _Swarm_AssignFromXML( self, cf, data );

   mesh           = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data );
   timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TimeIntegrator", TimeIntegrator, False, data );
   weights        = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"WeightsCalculator", WeightsCalculator, False, data );
   mapper         = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IntegrationPointMapper", IntegrationPointMapper, False, data );
   recalculateWeights = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"recalculateWeights", True );

   if( mapper !=NULL ) {
      Journal_Firewall (
         weights != NULL ||
         (weights == NULL && (Stg_Class_IsInstance( mapper, GaussMapper_Type ) ||
         Stg_Class_IsInstance( mapper, GaussCoincidentMapper_Type) ||
         !strcmp( mapper->type, "PCDVCGaussMapper"))),
         Journal_MyStream( Error_Type, self ),
         "In func %s, %s which is a %s must either have a %s or use %s\n",
         __func__,
         self->name,
         self->type,
         WeightsCalculator_Type,
         GaussMapper_Type );
   }
   
   context = (PICelleratorContext*)self->context;
   assert( Stg_CheckType( context, PICelleratorContext ) );
   materials_Register = context->materials_Register;
   assert( materials_Register );

   _IntegrationPointsSwarm_Init( self, mesh, timeIntegrator, weights, mapper, materials_Register, recalculateWeights );
}
void _StiffnessMatrixTerm_Init(
		void*                                                stiffnessMatrixTerm,
		FiniteElementContext*				                    context,
		StiffnessMatrix*                                     stiffnessMatrix,
		Swarm*                                               integrationSwarm,
		Stg_Component*                                       extraInfo )
{
	StiffnessMatrixTerm* self = (StiffnessMatrixTerm*)  stiffnessMatrixTerm;
	
	self->isConstructed		= True;
	self->context				= context;
	self->debug					= Journal_MyStream( Debug_Type, self );
	self->extraInfo			= extraInfo;	
	self->integrationSwarm	= integrationSwarm;	
	self->stiffnessMatrix	= stiffnessMatrix;
	self->max_nElNodes		= 0; /* initialise to zero, in assembly routine it will change value */
	self->GNx					= NULL;
    
    if(stiffnessMatrix)
      StiffnessMatrix_AddStiffnessMatrixTerm( stiffnessMatrix, self );
}
Ejemplo n.º 10
0
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" );

   }

}
/* remember this only has to initialise one cell of particles at a time */
void _TriGaussParticleLayout_InitialiseParticlesOfCell( void* triGaussParticleLayout, void* _swarm, Cell_Index cell_I )
{
	#define MAX_DIM 3
	#define MAX_GAUSS_POINTS_2D 1
	#define MAX_GAUSS_POINTS_3D 1
	TriGaussParticleLayout*   self = (TriGaussParticleLayout*)triGaussParticleLayout;
	Swarm*                    swarm = (Swarm*)_swarm;
	IntegrationPoint*         integrationPoint = NULL;

	Particle_InCellIndex      cParticle_I = 0;

	Particle_InCellIndex ppc;
	int dim;
	double weight[1];
	double xi[20][3];
	static int beenHere = 0;
	int d;
	
	dim = self->dim;
	ppc = self->particlesPerCell;
	
	if( dim == 2 ) {
		if( ppc == 1 ) {
			weight[0] = 0.5;

			xi[0][0] = 0.333333333333;
			xi[0][1] = 0.333333333333;				
		}
		if( ppc > MAX_GAUSS_POINTS_2D ) {
			Journal_Firewall(
				ppc > MAX_GAUSS_POINTS_2D,
				Journal_MyStream( Error_Type, self ),
				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
				__func__,
				MAX_GAUSS_POINTS_2D );
		}
	}
	else if ( dim == 3 ) {
		if( ppc == 1 ) {
			weight[0] = 0.5;			

			xi[0][0] = 0.333333333333;
			xi[0][1] = 0.333333333333;				
			xi[0][2] = 0.333333333333;				
		}
		if( ppc > MAX_GAUSS_POINTS_3D ) {
			Journal_Firewall(
				ppc > MAX_GAUSS_POINTS_3D,
				Journal_MyStream( Error_Type, self ),
				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
				__func__,
				MAX_GAUSS_POINTS_3D );
		}
	}

	assert( ppc <= swarm->cellParticleCountTbl[cell_I] );
	
	for ( cParticle_I = 0; cParticle_I < ppc; cParticle_I++ ) {
		integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
		integrationPoint->owningCell = cell_I;
			
		for( d = 0; d < dim; d++ ) {
			/*integrationPoint->coord[d] = xi[cParticle_I][d];*/
			integrationPoint->xi[d] = xi[cParticle_I][d];
		}
		
		integrationPoint->weight = weight[cParticle_I];
		
		beenHere = 1;
	}	
	
	
}