Exemple #1
0
void _MeshGenerator_Construct( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
	Dictionary*		dict;
	Dictionary_Entry_Value*	meshList;
	Mesh*			mesh;

	assert( self );
	assert( cf );

	/* Rip out the components structure as a dictionary. */
	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );

	/* Set the communicator to a default. */
	MeshGenerator_SetComm( self, MPI_COMM_WORLD );

	/* Read the individual mesh if specified. */
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, "mesh", Mesh, False, data );
	if( mesh )
		MeshGenerator_AddMesh( self, mesh );

	/* Read the mesh list, if it's there. */
	meshList = Dictionary_Get( dict, "meshes" );
	if( meshList ) {
		unsigned	nMeshes;
		char*		name;
		unsigned	m_i;

		nMeshes = Dictionary_Entry_Value_GetCount( meshList );
		for( m_i = 0; m_i < nMeshes; m_i++ ) {
			Mesh*	mesh;

			name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) );
			mesh = Stg_ComponentFactory_ConstructByName( cf, name, Mesh, True, data );
			MeshGenerator_AddMesh( self, mesh );
		}
	}

	/* Add to live component register. */
	LiveComponentRegister_Add( cf->LCRegister, (Stg_Component*)self );
}
void _MeshGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
	Dictionary*		dict;
	unsigned		nDims;
	Dictionary_Entry_Value*	meshList;
	Dictionary_Entry_Value	*enabledDimsList, *enabledIncList;
	Mesh*			mesh;
	Bool                    partitioned;

	assert( self );
	assert( cf );

	/* Rip out the components structure as a dictionary. */
	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );

	/* Set the communicator to a default. */
	partitioned = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"partitioned", 1  );
	if( partitioned ) {
		MeshGenerator_SetMPIComm( self, MPI_COMM_WORLD );
	}
	else {
		MeshGenerator_SetMPIComm( self, MPI_COMM_SELF );
	}

	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
	if( !self->context  )
		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, False, data  );

	/* Read the individual mesh if specified. */
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, False, data );
	if( mesh  )
		MeshGenerator_AddMesh( self, mesh );

	/* Read the mesh list, if it's there. */
	meshList = Dictionary_Get( dict, (Dictionary_Entry_Key)"meshes" );
	if( meshList ) {
		unsigned	nMeshes;
		char*		name;
		unsigned	m_i;

		nMeshes = Dictionary_Entry_Value_GetCount( meshList );
		for( m_i = 0; m_i < nMeshes; m_i++  ) {
			Mesh*	mesh;

			name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) );
			mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)name, Mesh, True, data  );
			MeshGenerator_AddMesh( self, mesh );
		}
	}

	/* Read dimensions and state. */
	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dim", 2 );
	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dims", nDims );
	MeshGenerator_SetDimSize( self, nDims );
	enabledDimsList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledDims"  );
	enabledIncList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledIncidence"  );

    /* Clear dims/incidence flags */
    unsigned    d_i;
    memset( self->enabledDims, 0, (nDims + 1) * sizeof(Bool) );
    for( d_i = 0; d_i <= nDims; d_i++ )
        memset( self->enabledInc[d_i], 0, (nDims + 1) * sizeof(Bool) );

    if( enabledDimsList ) {
        unsigned    dim;
        unsigned    nEnabledDims;
        nEnabledDims = Dictionary_Entry_Value_GetCount( enabledDimsList );
        for( d_i = 0; d_i < nEnabledDims; d_i++ ) {
            dim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledDimsList, d_i ) );
            if (dim > nDims)
                Journal_Printf(Mesh_Warning, "Warning - in %s: *** Skipping out of range dimension: %d\n", __func__, dim);
            else
                MeshGenerator_SetDimState( self, dim, True );
        }
    }
    else
    {
        /* Default to all dimensions enabled */
        for( d_i = 0; d_i < nDims + 1; d_i++ ) 
            MeshGenerator_SetDimState( self, d_i, True );
    }

    if( enabledIncList ) {
        unsigned    nEnabledInc;
        unsigned    fromDim, toDim;
        nEnabledInc = Dictionary_Entry_Value_GetCount( enabledIncList );
        assert( nEnabledInc % 2 == 0 );
        for( d_i = 0; d_i < nEnabledInc; d_i += 2 ) {
            fromDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i ) );
            toDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i + 1 ) );
            if (fromDim > nDims || toDim > nDims) 
                Journal_Printf( Mesh_Warning, "Warning - in %s: *** Skipping out of range incidence: %d to %d\n", 
                            __func__ , fromDim, toDim);
            else
                MeshGenerator_SetIncidenceState( self, fromDim, toDim, True );
        }
    }
    else
    {
        /* Default incidence setup 0->1,2,3  1->0,2  2->0,1  3->0,3 */
        MeshGenerator_SetIncidenceState( self, 0, 0, True );
        for( d_i = 1; d_i <= nDims; d_i ++ ) {
            MeshGenerator_SetIncidenceState( self, 0, d_i, True );
            MeshGenerator_SetIncidenceState( self, d_i, 0, True );
        }
        if (nDims == 2) {
            MeshGenerator_SetIncidenceState( self, 1, 2, True );
            MeshGenerator_SetIncidenceState( self, 2, 1, True );
            MeshGenerator_SetIncidenceState( self, 2, 2, True );
        }
        if( nDims == 3 )
           MeshGenerator_SetIncidenceState( self, 3, 3, True );
    }
}