void _VariableCondition_Build( void* variableCondition, void* data ) { VariableCondition* self = (VariableCondition*)variableCondition; VariableCondition_ValueIndex val_I; Index i; /* Read the dictionary */ self->_readDictionary( self, self->dictionary ); /* Obtain the set */ self->_set = self->_getSet(self); if (self->_set) IndexSet_GetMembers(self->_set, &self->indexCount, &self->indexTbl); else { self->indexCount = 0; self->indexTbl = NULL; } /* Only build the index related tables if there are active BCs */ if ( self->indexCount ) { /* Build the variable to condition table */ self->vcVarCountTbl = Memory_Alloc_Array( VariableCondition_VariableIndex, self->indexCount, "VC->vcVarCountTbl" ); for (i = 0; i < self->indexCount; i++) { /* For the index, get the number of "variables" that have been assigned conditions */ self->vcVarCountTbl[i] = self->_getVariableCount(self, self->indexTbl[i]); } self->vcTbl = Memory_Alloc_2DComplex( VariableCondition_Tuple, self->indexCount, self->vcVarCountTbl, "VC->vcTbl" ); for ( i = 0; i < self->indexCount; i++ ) { VariableCondition_VariableIndex vcVar_I; for ( vcVar_I = 0; vcVar_I < self->vcVarCountTbl[i]; vcVar_I++ ) { Variable* var; /* For the index's variable, get the variable i.d. and value i.d. */ self->vcTbl[i][vcVar_I].varIndex = self->_getVariableIndex(self, self->indexTbl[i], vcVar_I); self->vcTbl[i][vcVar_I].valIndex = self->_getValueIndex(self, self->indexTbl[i], vcVar_I); /* Force the building of the variable (to be safe) */ var = self->variable_Register->_variable[self->vcTbl[i][vcVar_I].varIndex]; Stg_Component_Build( var, data, False ); } } } self->valueCount = self->_getValueCount(self); self->valueTbl = Memory_Alloc_Array( VariableCondition_Value, self->valueCount, "VC->valueTbl" ); for (val_I = 0; val_I < self->valueCount; val_I++) self->valueTbl[val_I] = self->_getValue(self, val_I); /* Build mapping. */ self->mapping = UIntMap_New(); for( i = 0; i < self->indexCount; i++ ) UIntMap_Insert( self->mapping, self->indexTbl[i], i ); }
Fn::MeshIndexSet::MeshIndexSet( IndexSet* indexSet, void* mesh ) : IOIterator(), _indexSet(indexSet), _mesh(mesh), _indexArray(NULL) { if(!Stg_Class_IsInstance( mesh, Mesh_Type )) throw std::invalid_argument("Provided 'mesh' does not appear to be of 'Mesh' type."); if(!Stg_Class_IsInstance( indexSet, IndexSet_Type )) throw std::invalid_argument("Provided 'indexSet' does not appear to be of 'IndexSet' type."); // get array from index set IndexSet_GetMembers( _indexSet, &_size, &_indexArray ); }
void _SnacRemesher_InterpolateNodes( void* _context ) { 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 ); NodeLayout* nLayout = mesh->layout->nodeLayout; Node_LocalIndex newNode_i; IndexSet* extNodes; void interpolateNode( void* _context, Node_LocalIndex newNodeInd, Element_DomainIndex dEltInd ); /* ** Free any owned arrays that may still exist from the last node interpolation. */ FreeArray( meshExt->externalNodes ); meshExt->nExternalNodes = 0; /* ** Scoot over all the new nodes and find the old element in which each one resides, then interpolate. */ /* Create an index set for storing any external nodes. */ extNodes = IndexSet_New( mesh->nodeLocalCount ); for( newNode_i = 0; newNode_i < mesh->nodeLocalCount; newNode_i++ ) { Node_LocalIndex dNodeInd; unsigned nElements; Element_DomainIndex* elements; Coord newPoint; unsigned elt_i; /* Extract the new node's coordinate. */ Vector_Set( newPoint, meshExt->newNodeCoords[newNode_i] ); /* Find the closest old node. */ dNodeInd = findClosestNode( context, newPoint, newNode_i ); /* Grab incident elements. */ { Node_GlobalIndex gNodeInd; gNodeInd = Mesh_NodeMapDomainToGlobal( mesh, dNodeInd ); nElements = nLayout->nodeElementCount( nLayout, gNodeInd ); if( nElements ) { elements = Memory_Alloc_Array( Element_DomainIndex, nElements, "SnacRemesher" ); nLayout->buildNodeElements( nLayout, gNodeInd, elements ); } else { elements = NULL; } } /* Convert global element indices to domain. */ for( elt_i = 0; elt_i < nElements; elt_i++ ) { elements[elt_i] = Mesh_ElementMapGlobalToDomain( mesh, elements[elt_i] ); } /* Which of the incident elements contains the node? */ for( elt_i = 0; elt_i < nElements; elt_i++ ) { if( elements[elt_i] >= mesh->elementDomainCount ) { continue; } if( pointInElement( context, newPoint, elements[elt_i] ) ) { break; } } /* Did we find the element? */ if( elt_i < nElements ) { /* If so, call a function to locate the tetrahedra and interpolate. */ interpolateNode( context, newNode_i, elements[elt_i] ); } else { /* If not, then the new node finds itself outside the old mesh. In this scenario, we cannot interpolate the nodal values with any accuracy (without knowing more about the physical problem). So, we will leave the node with its old values and mark this node as not being interpolated so the user may deal with it. */ /* Stash the node index. */ IndexSet_Add( extNodes, newNode_i ); /* Copy across the old value. Note that this should be done using some other provided copy method. */ memcpy( (unsigned char*)meshExt->newNodes + newNode_i * mesh->nodeExtensionMgr->finalSize, (unsigned char*)mesh->node + newNode_i * mesh->nodeExtensionMgr->finalSize, mesh->nodeExtensionMgr->finalSize ); /* assert(0); */ } /* Free element array. */ FreeArray( elements ); } /* Dump the external nodes and delete the set. */ IndexSet_GetMembers( extNodes, &meshExt->nExternalNodes, &meshExt->externalNodes ); Stg_Class_Delete( extNodes ); }