void DictionarySuite_TestSet( DictionarySuiteData* data ) { Dictionary_Entry_Value* currValue; Dictionary_Entry_Value* listValue; double newVal1 = 34.3, newVal2 = 38.9; Index ii=0; DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD ); listValue = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_list" ); /* getting dictionary out of a list */ currValue = Dictionary_Entry_Value_GetFirstElement( listValue ); /* do something to this value */ Dictionary_Entry_Value_SetFromDouble( currValue, newVal1 ); currValue = currValue->next; /* do something to this value */ Dictionary_Entry_Value_SetFromDouble( currValue, newVal2 ); pcu_check_true( 5 == Dictionary_Entry_Value_GetCount( listValue ) ); currValue = Dictionary_Entry_Value_GetFirstElement( listValue ); pcu_check_le( fabs(newVal1 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 ); currValue = currValue->next; pcu_check_le( fabs(newVal2 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 ); currValue = currValue->next; for ( ii=2; ii<data->testDD->testListCount; ii++ ) { pcu_check_le( fabs(data->testDD->testList[ii] - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 ); currValue = currValue->next; } }
void DictionarySuite_TestAddElement( DictionarySuiteData* data ) { Dictionary_Entry_Value* yValue; Dictionary_Entry_Value* testStruct; Dictionary_Entry_Value* currValue; double newVal = -45.0; DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD ); /* turning the starty value into a list using add element */ testStruct = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct" ); yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, (Dictionary_Entry_Key)"geom" ), "starty"); Dictionary_Entry_Value_AddElement( yValue, Dictionary_Entry_Value_FromDouble(newVal) ); pcu_check_true( Dictionary_Entry_Value_Type_List == yValue->type ); pcu_check_true( 2 == Dictionary_Entry_Value_GetCount( yValue ) ); currValue = Dictionary_Entry_Value_GetFirstElement( yValue ); pcu_check_le( fabs( data->testDD->testStruct->geom.starty - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 ); currValue = currValue->next; pcu_check_le( fabs( newVal - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 ); }
void _SnacHillSlope_InitialConditions( void* _context, void* data ) { Snac_Context *context = (Snac_Context*)_context; SnacHillSlope_Context *contextExt = ExtensionManager_Get(context->extensionMgr, context, SnacHillSlope_ContextHandle ); Mesh *mesh = context->mesh; MeshLayout *layout = (MeshLayout*)mesh->layout; HexaMD *decomp = (HexaMD*)layout->decomp; BlockGeometry *geometry = (BlockGeometry*)layout->elementLayout->geometry; Node_GlobalIndex node_g, node_gI, node_gJ; const int full_I_node_range=decomp->nodeGlobal3DCounts[0]; const int full_J_node_range=decomp->nodeGlobal3DCounts[1]; double new_x[full_I_node_range], new_y[full_J_node_range]; double reg_dx, reg_dy, new_xMax, new_xMin, new_xHalf, midOffset, old_yMax, new_yMax, new_yMin; double slopeAngle = contextExt->slopeAngle * M_PI/180.0; double resolveHeight = geometry->max[1]-contextExt->resolveDepth; double xLeftFlatRamp = (contextExt->leftFlatFraction<0.0 ? 0.0 : (contextExt->leftFlatFraction>1.0 ? 1.0 : contextExt->leftFlatFraction)); double xRightRampFlat = (contextExt->rightFlatFraction<0.0 ? 1.0-contextExt->leftFlatFraction : (contextExt->rightFlatFraction>1.0 ? 1.0 : contextExt->rightFlatFraction)); const double smoothFactor = contextExt->rampFlatSmoothFactor; int restart = FALSE; Dictionary_Entry_Value *pluginsList, *plugin; #ifdef DEBUG int imax=0; #endif pluginsList = PluginsManager_GetPluginsList( context->dictionary ); if (pluginsList) { plugin = Dictionary_Entry_Value_GetFirstElement(pluginsList); while ( plugin ) { if ( 0 == strcmp( Dictionary_Entry_Value_AsString( plugin ), "SnacRestart" ) ) { restart = TRUE; break; } plugin = plugin->next; } } /* if(context->restartTimestep > 0) { restart = TRUE; } */ if( restart ) { fprintf(stderr, "Restarting: thus bailing from hillSlope/InitialConditions.c to avoid overwriting the mesh geometry\n"); return; } #ifdef DEBUG printf( "In: %s\n", __func__ ); #endif // fprintf(stderr, "Slope angle = %g degrees\n", slopeAngle/(M_PI/180.0)); /* Report HillSlope plugin variables picked up (?) from xml parameter file */ Journal_Printf( context->snacInfo, "\nSlope angle = %g degrees\n", slopeAngle/(M_PI/180.0) ); reg_dx = (geometry->max[0]-geometry->min[0])/(double)(full_I_node_range-1); reg_dy = (geometry->max[1]-geometry->min[1])/(double)(full_J_node_range-1); /* * Decide at what height (prior to shearing) to switch from rombhoid to parallelopiped geometry, * i.e., at what depth to resolve using "regular" elements parallel to the surface * versus "irregular" elements deformed to fit to a horizontal bottom * If contextExt->resolveDepth is negative, resolveHeight is set to zero and the whole domain is "regular" */ if(contextExt->resolveDepth<0.0 || resolveHeight<0.0) { resolveHeight = 0.0; } else if(resolveHeight>geometry->max[1]) { resolveHeight = geometry->max[1]; } for( node_gI = 0; node_gI < full_I_node_range; node_gI++ ) new_x[node_gI] = geometry->min[0] + node_gI*reg_dx; for( node_gJ = 0; node_gJ <= (full_J_node_range-1); node_gJ++ ) new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy; /* if((full_J_node_range-1)<4) { */ /* for( node_gJ = 0; node_gJ <= (full_J_node_range-1); node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy; */ /* } else { */ /* for( node_gJ = 0; node_gJ <= (full_J_node_range-1)/4; node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy*(stretchFactor/(1.0+stretchFactor)); */ /* for( ; node_gJ <= (full_J_node_range-1); node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + ((full_J_node_range-1)/4)*reg_dy*(stretchFactor/(1.0+stretchFactor)) */ /* + (node_gJ-((full_J_node_range-1)/4))*reg_dy*(1.0/(1.0+stretchFactor)); */ /* } */ /* * Assume highest point in x,y is at the last mesh node */ new_xMin = new_x[0]; new_xMax = new_x[full_I_node_range-1]; new_xHalf = new_xMin+(new_xMax-new_xMin)/2.0; new_yMin = new_y[0]; old_yMax = new_yMax = new_y[full_J_node_range-1]; /*+ tan(mesh_slope)*geometry->max[0]; */ xLeftFlatRamp=new_xMin+(new_xMax-new_xMin)*xLeftFlatRamp; xRightRampFlat=new_xMin+(new_xMax-new_xMin)*xRightRampFlat; fprintf(stderr, "Left flat <= %g -> %g\n", contextExt->leftFlatFraction, xLeftFlatRamp); fprintf(stderr, "Right flat >= %g -> %g\n", contextExt->rightFlatFraction, xRightRampFlat); fprintf(stderr, "Ramp-flat smoothness = %g\n", smoothFactor); fprintf(stderr, "Flat/ramp/flat ranges: %g <-> %g <-> %g <-> %g\n", new_xMin, xLeftFlatRamp, xRightRampFlat, new_xMax); /* * Loop across all nodes in mesh * - total of x*y*z nodes is given by context->mesh->nodeGlobalCount+1 */ for( node_g = 0; node_g < context->mesh->nodeGlobalCount; node_g++ ) { Node_LocalIndex node_l = Mesh_NodeMapGlobalToLocal( mesh, node_g ); Index i_g; Index j_g; Index k_g; Coord* coord = 0; Coord tmpCoord; /* * If a local node, directly change the node coordinates else use a temporary location */ if( node_l < context->mesh->nodeLocalCount ) { /* a local node */ coord = Snac_NodeCoord_P( context, node_l ); } else { /* * If the node is running on another CPU, use dummy ptr * - wouldn't it be better to just skip (continue) to next node? */ coord = &tmpCoord; } /* * Convert 1d mesh node index to 3d i,j,k mesh node position */ RegularMeshUtils_Node_1DTo3D( decomp, node_g, &i_g, &j_g, &k_g ); /* * Do nothing to x coordinate */ (*coord)[0] = new_x[i_g]; /*exp(-smoothFactor*(xRightRampFlat-new_x[i_g])/old_yMax) * Transform y coordinates by shearing mesh parallel to vertical axis */ (*coord)[1] = new_y[j_g]; midOffset=( (xRightRampFlat-(xRightRampFlat-new_xHalf)*( 1.0-exp(-smoothFactor*(xRightRampFlat-new_xHalf)/old_yMax) )) - (new_xHalf-xLeftFlatRamp)*( 1.0-exp(-smoothFactor*(new_xHalf-xLeftFlatRamp)/old_yMax) ) )*tan(slopeAngle); if(new_x[i_g]<=new_xHalf) { /* LHS */ (*coord)[1] += ( (new_x[i_g]<xLeftFlatRamp ? 0 : (new_x[i_g]-xLeftFlatRamp)*( 1.0-exp(-smoothFactor*(new_x[i_g]-xLeftFlatRamp)/old_yMax) )*tan(slopeAngle) ) *(new_y[j_g]>=resolveHeight ? 1.0 : new_y[j_g]/resolveHeight) ); } else { /* RHS */ (*coord)[1] += ( (new_x[i_g]>=xRightRampFlat ? xRightRampFlat*tan(slopeAngle)-midOffset : (xRightRampFlat-(xRightRampFlat-new_x[i_g])*( 1.0-exp(-smoothFactor*(xRightRampFlat-new_x[i_g])/old_yMax) ))*tan(slopeAngle) - midOffset) *(new_y[j_g]>=resolveHeight ? 1.0 : new_y[j_g]/resolveHeight) ); } /* * Track maximum y as mesh deforms */ if((*coord)[1]>new_yMax) new_yMax=(*coord)[1]; #ifdef DEBUG fprintf( stderr, "\tnode_l: %2u, node_g: %2u, i: %2u, j: %2u, k: %2u, ", node_l, node_g, i_g, j_g, k_g ); fprintf( stderr, "x: %12g, y: %12g, z: %12g\n", (*coord)[0], (*coord)[1], (*coord)[2] ); #endif } /* * Reset vertical max */ geometry->max[1] = new_yMax; }