void exprTri1 (syn_ctx * ctx, char *name) { char *buf = cell_name ("TRI"); if (!name) { //create definition if (!exists (ctx, buf)) { o_p ("(cell %s (celltype GENERIC)\n", buf); i_i (); o_p ("(view netlist (viewtype NETLIST)\n"); i_i (); o_p ("(interface\n"); i_i (); o_p ("(port Q (direction OUTPUT))\n"); //output o_p ("(port A (direction INPUT))\n"); //input o_p ("(port ENA (direction INPUT))\n"); //ctrl i_d (); o_p (")\n"); //interface i_d (); //builtin, no contents o_p (")\n"); //view i_d (); o_p (")\n"); //cell hash_put (ctx, buf); } } else { o_p ("(instance %s (viewref netlist (cellref %s (libraryref DESIGNS))))\n", name, buf); } free (buf); }
void tbl_bufif (syn_ctx * ctx, char *name, int width, Opdesc const *op) { char *buf = cell_name ("%s_%d", op->name, width); assert (width > 0); if (!name) { //create definition if (!exists (ctx, buf)) { int i; char *inv1 = NULL; char **inv_en = NULL; char **tris = NULL; if (op->buf_pol) { exprInv (ctx, NULL, width); } if (!op->en_pol) { exprInv (ctx, NULL, 1); } exprTri1 (ctx, NULL); o_p ("(cell %s (celltype GENERIC)\n", buf); i_i (); o_p ("(view netlist (viewtype NETLIST)\n"); i_i (); o_p ("(interface\n"); i_i (); for (i = 0; i < width; i++) o_p ("(port A_%d (direction INPUT))\n", i); //inputs for (i = 0; i < width; i++) o_p ("(port B_%d (direction INPUT))\n", i); //the enable for (i = 0; i < width; i++) o_p ("(port Q_%d (direction OUTPUT))\n", i); //outputs i_d (); o_p (")\n"); //interface o_p ("(contents\n"); i_i (); if (op->buf_pol) { inv1 = l_n (); exprInv (ctx, inv1, width); } if (!op->en_pol) { inv_en = calloc (width, sizeof (char *)); assert (inv_en); for (i = 0; i < width; i++) { inv_en[i] = l_n (); exprInv (ctx, inv_en[i], 1); } } tris = calloc (width, sizeof (char *)); assert (tris); for (i = 0; i < width; i++) { tris[i] = l_n (); exprTri1 (ctx, tris[i]); } if (op->buf_pol) { for (i = 0; i < width; i++) { n_n (); o_p ("(portref A_%d)\n", i); o_p ("(portref A_%d (instanceref %s))\n", i, inv1); n_e (); n_n (); o_p ("(portref Q_%d (instanceref %s))\n", i, inv1); o_p ("(portref A (instanceref %s))\n", tris[i]); n_e (); } } else { for (i = 0; i < width; i++) { n_n (); o_p ("(portref A_%d)\n", i); o_p ("(portref A (instanceref %s))\n", tris[i]); n_e (); } } if (!op->en_pol) { for (i = 0; i < width; i++) { n_n (); o_p ("(portref B_%d)\n"); o_p ("(portref A (instanceref %s))\n", inv_en[i]); n_e (); n_n (); o_p ("(portref Q (instanceref %s))\n", inv_en[i]); o_p ("(portref ENA (instanceref %s))\n", tris[i]); n_e (); } } else { for (i = 0; i < width; i++) { n_n (); o_p ("(portref B_%d)\n", i); o_p ("(portref ENA (instanceref %s))\n", tris[i]); n_e (); } } for (i = 0; i < width; i++) { n_n (); o_p ("(portref Q (instanceref %s))\n", tris[i]); o_p ("(portref Q_%d)\n", i); n_e (); } i_d (); o_p (")\n"); //contents i_d (); o_p (")\n"); //view i_d (); o_p (")\n"); //cell hash_put (ctx, buf); for (i = 0; i < width; i++) free (tris[i]); free (tris); if (!op->en_pol) { for (i = 0; i < width; i++) free (inv_en[i]); free (inv_en); } if (op->buf_pol) free (inv1); } } else { o_p ("(instance %s (viewref netlist (cellref %s (libraryref DESIGNS))))\n", name, buf); } free (buf); }
void INSStaggeredPressureBcCoef::setBcCoefs(Pointer<ArrayData<NDIM, double> >& acoef_data, Pointer<ArrayData<NDIM, double> >& bcoef_data, Pointer<ArrayData<NDIM, double> >& gcoef_data, const Pointer<Variable<NDIM> >& variable, const Patch<NDIM>& patch, const BoundaryBox<NDIM>& bdry_box, double /*fill_time*/) const { #if !defined(NDEBUG) for (unsigned int d = 0; d < NDIM; ++d) { TBOX_ASSERT(d_bc_coefs[d]); } TBOX_ASSERT(acoef_data); TBOX_ASSERT(bcoef_data); #endif Box<NDIM> bc_coef_box = acoef_data->getBox(); #if !defined(NDEBUG) TBOX_ASSERT(bc_coef_box == acoef_data->getBox()); TBOX_ASSERT(bc_coef_box == bcoef_data->getBox()); TBOX_ASSERT(!gcoef_data || (bc_coef_box == gcoef_data->getBox())); #endif // Set the unmodified velocity bc coefs. const unsigned int location_index = bdry_box.getLocationIndex(); const unsigned int bdry_normal_axis = location_index / 2; const bool is_lower = location_index % 2 == 0; const double half_time = d_fluid_solver->getIntegratorTime() + 0.5 * d_fluid_solver->getCurrentTimeStepSize(); d_bc_coefs[bdry_normal_axis]->setBcCoefs( acoef_data, bcoef_data, gcoef_data, variable, patch, bdry_box, half_time); // Ensure homogeneous boundary conditions are enforced. if (d_homogeneous_bc && gcoef_data) gcoef_data->fillAll(0.0); // Get the target velocity data. Pointer<SideData<NDIM, double> > u_target_data; if (d_u_target_data_idx >= 0) u_target_data = patch.getPatchData(d_u_target_data_idx); else if (d_target_data_idx >= 0) u_target_data = patch.getPatchData(d_target_data_idx); #if !defined(NDEBUG) TBOX_ASSERT(u_target_data); #endif Pointer<SideData<NDIM, double> > u_current_data = patch.getPatchData( d_fluid_solver->getVelocityVariable(), d_fluid_solver->getCurrentContext()); #if !defined(NDEBUG) TBOX_ASSERT(u_current_data); #endif const Box<NDIM> ghost_box = u_target_data->getGhostBox() * u_current_data->getGhostBox(); for (unsigned int d = 0; d < NDIM; ++d) { if (d != bdry_normal_axis) { bc_coef_box.lower(d) = std::max(bc_coef_box.lower(d), ghost_box.lower(d)); bc_coef_box.upper(d) = std::min(bc_coef_box.upper(d), ghost_box.upper(d)); } } // Update the boundary condition coefficients. Normal velocity boundary // conditions are converted into Neumann conditions for the pressure, and // normal traction boundary conditions are converted into Dirichlet // conditions for the pressure. const double mu = d_fluid_solver->getStokesSpecifications()->getMu(); Pointer<CartesianPatchGeometry<NDIM> > pgeom = patch.getPatchGeometry(); const double* const dx = pgeom->getDx(); for (Box<NDIM>::Iterator it(bc_coef_box); it; it++) { const Index<NDIM>& i = it(); double dummy_val; double& alpha = acoef_data ? (*acoef_data)(i, 0) : dummy_val; double& beta = bcoef_data ? (*bcoef_data)(i, 0) : dummy_val; double& gamma = gcoef_data ? (*gcoef_data)(i, 0) : dummy_val; const bool velocity_bc = MathUtilities<double>::equalEps(alpha, 1.0); const bool traction_bc = MathUtilities<double>::equalEps(beta, 1.0); #if !defined(NDEBUG) TBOX_ASSERT((velocity_bc || traction_bc) && !(velocity_bc && traction_bc)); #endif if (velocity_bc) { alpha = 0.0; beta = 1.0; gamma = 0.0; } else if (traction_bc) { switch (d_traction_bc_type) { case TRACTION: // -p + 2*mu*du_n/dx_n = g. { // Place i_i in the interior cell abutting the boundary, and // place i_g in the ghost cell abutting the boundary. Index<NDIM> i_i(i), i_g(i); if (is_lower) { i_g(bdry_normal_axis) -= 1; } else { i_i(bdry_normal_axis) -= 1; } // The boundary condition is -p + 2*mu*du_n/dx_n = g. // // Because p is centered about t^{n+1/2}, we compute this // as: // // p^{n+1/2} = mu*du_n/dx_n^{n} + mu*du_n/dx_n^{n+1} - g^{n+1/2}. static const int NVALS = 3; double u_current[NVALS], u_new[NVALS]; SideIndex<NDIM> i_s(i_i, bdry_normal_axis, is_lower ? SideIndex<NDIM>::Lower : SideIndex<NDIM>::Upper); for (int k = 0; k < NVALS; ++k, i_s(bdry_normal_axis) += (is_lower ? 1 : -1)) { u_current[k] = (*u_current_data)(i_s); u_new[k] = (*u_target_data)(i_s); } const double h = dx[bdry_normal_axis]; const double du_norm_current_dx_norm = (is_lower ? +1.0 : -1.0) * (2.0 * u_current[1] - 1.5 * u_current[0] - 0.5 * u_current[2]) / h; const double du_norm_new_dx_norm = (is_lower ? +1.0 : -1.0) * (2.0 * u_new[1] - 1.5 * u_new[0] - 0.5 * u_new[2]) / h; alpha = 1.0; beta = 0.0; gamma = (d_homogeneous_bc ? 0.0 : mu * du_norm_current_dx_norm) + mu * du_norm_new_dx_norm - gamma; break; } case PSEUDO_TRACTION: // -p = g. { alpha = 1.0; beta = 0.0; gamma = -gamma; break; } default: { TBOX_ERROR( "INSStaggeredPressureBcCoef::setBcCoefs(): unrecognized or unsupported " "traction boundary condition type: " << enum_to_string<TractionBcType>(d_traction_bc_type) << "\n"); } } } else { TBOX_ERROR("this statement should not be reached!\n"); } } return; } // setBcCoefs
void int_tests (void) { av_alist a; int ir; ir = i_v(); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_v,&ir); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); ir = i_i(i1); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_i,&ir); av_int(a,i1); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); ir = i_i2(i1,i2); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_i2,&ir); av_int(a,i1); av_int(a,i2); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); ir = i_i4(i1,i2,i3,i4); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_i4,&ir); av_int(a,i1); av_int(a,i2); av_int(a,i3); av_int(a,i4); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); ir = i_i8(i1,i2,i3,i4,i5,i6,i7,i8); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_i8,&ir); av_int(a,i1); av_int(a,i2); av_int(a,i3); av_int(a,i4); av_int(a,i5); av_int(a,i6); av_int(a,i7); av_int(a,i8); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); ir = i_i16(i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16); fprintf(out,"->%d\n",ir); fflush(out); ir = 0; clear_traces(); av_start_int(a,i_i16,&ir); av_int(a,i1); av_int(a,i2); av_int(a,i3); av_int(a,i4); av_int(a,i5); av_int(a,i6); av_int(a,i7); av_int(a,i8); av_int(a,i9); av_int(a,i10); av_int(a,i11); av_int(a,i12); av_int(a,i13); av_int(a,i14); av_int(a,i15); av_int(a,i16); av_call(a); fprintf(out,"->%d\n",ir); fflush(out); return; }