static void parse_rollback(struct vcc *tl) { vcc_NextToken(tl); Fb(tl, 1, "VRT_Rollback(ctx, VRT_r_req(ctx));\n"); }
static void parse_ban(struct vcc *tl) { vcc_NextToken(tl); ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_ban_string(sp, "); vcc_Expr(tl, STRING); ERRCHK(tl); Fb(tl, 0, ");\n"); ExpectErr(tl, ')'); vcc_NextToken(tl); }
static void parse_set(struct vcc *tl) { const struct symbol *sym; const struct arith *ap; vcc_type_t fmt; vcc_NextToken(tl); ExpectErr(tl, ID); sym = vcc_FindVar(tl, tl->t, 1, "cannot be set"); ERRCHK(tl); assert(sym != NULL); if (vcc_IdIs(tl->t, "bereq.body")) { VSB_printf(tl->sb, "bereq.body cannot be set.\n"); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 1, "%s\n", sym->lname); tl->indent += INDENT; vcc_NextToken(tl); fmt = sym->fmt; for (ap = arith; ap->type != VOID; ap++) { if (ap->type != fmt) continue; if (ap->oper != tl->t->tok) continue; if (ap->oper != '=') Fb(tl, 1, "%s %c ", sym->rname, *tl->t->b); vcc_NextToken(tl); fmt = ap->want; break; } if (ap->type == VOID) SkipToken(tl, ap->oper); if (fmt == HEADER) { vcc_Expr(tl, STRING_LIST); } else if (fmt == STRING) { vcc_Expr(tl, STRING_LIST); } else if (fmt == BODY) { vcc_Expr(tl, STRING_LIST); } else { vcc_Expr(tl, fmt); } tl->indent -= INDENT; Fb(tl, 1, ");\n"); }
static void parse_purge_url(struct tokenlist *tl) { vcc_NextToken(tl); ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_ban(sp, \"req.url\", \"~\", "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } ExpectErr(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 0);\n"); }
static void vcc_IfStmt(struct vcc *tl) { SkipToken(tl, ID); Fb(tl, 1, "if "); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); while (tl->t->tok == ID) { if (vcc_IdIs(tl->t, "else")) { vcc_NextToken(tl); if (tl->t->tok == '{') { Fb(tl, 1, "else\n"); L(tl, vcc_Compound(tl)); ERRCHK(tl); return; } if (tl->t->tok != ID || !vcc_IdIs(tl->t, "if")) { VSB_printf(tl->sb, "'else' must be followed by 'if' or '{'\n"); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); } else if (vcc_IdIs(tl->t, "elseif") || vcc_IdIs(tl->t, "elsif") || vcc_IdIs(tl->t, "elif")) { Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); } else { break; } } C(tl, ";"); }
static void parse_error(struct vcc *tl) { vcc_NextToken(tl); Fb(tl, 1, "VRT_error(sp,\n"); if (tl->t->tok == '(') { vcc_NextToken(tl); vcc_Expr(tl, INT); if (tl->t->tok == ',') { Fb(tl, 1, ",\n"); vcc_NextToken(tl); vcc_Expr(tl, STRING); } else Fb(tl, 1, ", 0\n"); SkipToken(tl, ')'); } else { vcc_Expr(tl, INT); if (tl->t->tok != ';') { Fb(tl, 1, ",\n"); vcc_Expr(tl, STRING); } else Fb(tl, 1, ", 0\n"); } Fb(tl, 1, ");\n"); Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n"); }
static void parse_restart(struct tokenlist *tl) { struct token *t1; t1 = VTAILQ_NEXT(tl->t, list); if (t1->tok == ID && vcc_IdIs(t1, "rollback")) { Fb(tl, 1, "VRT_Rollback(sp);\n"); vcc_NextToken(tl); } else if (t1->tok != ';') { vsb_printf(tl->sb, "Expected \"rollback\" or semicolon.\n"); vcc_ErrWhere(tl, t1); ERRCHK(tl); } Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n"); vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t); vcc_NextToken(tl); }
static void parse_synthetic(struct vcc *tl) { vcc_NextToken(tl); ExpectErr(tl, '('); ERRCHK(tl); vcc_NextToken(tl); Fb(tl, 1, "VRT_synth_page(ctx, "); vcc_Expr(tl, STRING_LIST); ERRCHK(tl); Fb(tl, 0, ");\n"); ExpectErr(tl, ')'); vcc_NextToken(tl); ERRCHK(tl); }
static void parse_ban(struct vcc *tl) { vcc_NextToken(tl); ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_ban_string(ctx, \n"); tl->indent += INDENT; vcc_Expr(tl, STRING); tl->indent -= INDENT; ERRCHK(tl); Fb(tl, 1, ");\n"); ExpectErr(tl, ')'); vcc_NextToken(tl); }
static void Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const struct token *t_port) { const char *ipv4, *ipv4a, *ipv6, *ipv6a, *pa; char buf[256]; AN(t_host->dec); if (t_port != NULL) bprintf(buf, "%s %s", t_host->dec, t_port->dec); else bprintf(buf, "%s", t_host->dec); Resolve_Sockaddr(tl, buf, "80", &ipv4, &ipv4a, &ipv6, &ipv6a, &pa, 2, t_host, "Backend host"); ERRCHK(tl); if (ipv4 != NULL) { Fb(tl, 0, "\t.ipv4_suckaddr = (const struct suckaddr *)%s,\n", ipv4); Fb(tl, 0, "\t.ipv4_addr = \"%s\",\n", ipv4a); } if (ipv6 != NULL) { Fb(tl, 0, "\t.ipv6_suckaddr = (const struct suckaddr *)%s,\n", ipv6); Fb(tl, 0, "\t.ipv6_addr = \"%s\",\n", ipv6a); } Fb(tl, 0, "\t.port = \"%s\",\n", pa); Fb(tl, 0, "\t.path = (void *) 0,\n"); }
static void parse_set(struct vcc *tl) { const struct var *vp; const struct arith *ap; enum var_type fmt; vcc_NextToken(tl); ExpectErr(tl, ID); vp = vcc_FindVar(tl, tl->t, 1, "cannot be set"); ERRCHK(tl); assert(vp != NULL); Fb(tl, 1, "%s\n", vp->lname); tl->indent += INDENT; vcc_NextToken(tl); fmt = vp->fmt; for (ap = arith; ap->type != VOID; ap++) { if (ap->type != fmt) continue; if (ap->oper != tl->t->tok) continue; if (ap->oper != '=') Fb(tl, 1, "%s %c ", vp->rname, *tl->t->b); vcc_NextToken(tl); fmt = ap->want; break; } if (ap->type == VOID) SkipToken(tl, ap->oper); if (fmt == HEADER) { vcc_Expr(tl, STRING_LIST); } else if (fmt == STRING) { vcc_Expr(tl, STRING_LIST); } else { vcc_Expr(tl, fmt); } tl->indent -= INDENT; Fb(tl, 1, ");\n"); }
static void parse_return_synth(struct vcc *tl) { ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_synth(ctx,\n"); tl->indent += INDENT; vcc_Expr(tl, INT); ERRCHK(tl); Fb(tl, 1, ",\n"); if (tl->t->tok == ',') { vcc_NextToken(tl); vcc_Expr(tl, STRING); ERRCHK(tl); } else { Fb(tl, 1, "(const char*)0\n"); } tl->indent -= INDENT; ExpectErr(tl, ')'); vcc_NextToken(tl); Fb(tl, 1, ");\n"); }
static void vcc_IfStmt(struct vcc *tl) { SkipToken(tl, T_IF); Fb(tl, 1, "if "); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); while (1) { switch (tl->t->tok) { case T_ELSE: vcc_NextToken(tl); if (tl->t->tok != T_IF) { Fb(tl, 1, "else\n"); L(tl, vcc_Compound(tl)); ERRCHK(tl); return; } /* FALLTHROUGH */ case T_ELSEIF: case T_ELSIF: Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); break; default: C(tl, ";"); return; } } }
static void parse_error(struct tokenlist *tl) { struct var *vp; vcc_NextToken(tl); if (tl->t->tok == VAR) { vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); if (vp->fmt == INT) { Fb(tl, 1, "VRT_error(sp, %s", vp->rname); vcc_NextToken(tl); } else { Fb(tl, 1, "VRT_error(sp, 0"); } } else if (tl->t->tok == CNUM) { Fb(tl, 1, "VRT_error(sp, %u", vcc_UintVal(tl)); } else Fb(tl, 1, "VRT_error(sp, 0"); if (tl->t->tok == CSTR) { Fb(tl, 0, ", %.*s", PF(tl->t)); vcc_NextToken(tl); } else if (tl->t->tok == VAR) { Fb(tl, 0, ", "); if (!vcc_StringVal(tl)) { ERRCHK(tl); vcc_ExpectedStringval(tl); return; } } else { Fb(tl, 0, ", (const char *)0"); } Fb(tl, 0, ");\n"); Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n"); }
static void parse_unset(struct tokenlist *tl) { struct var *vp; vcc_NextToken(tl); ExpectErr(tl, VAR); vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); if (vp->fmt != STRING || vp->hdr == NULL) { vsb_printf(tl->sb, "Only http header lines can be unset.\n"); vcc_ErrWhere(tl, tl->t); return; } check_writebit(tl, vp); ERRCHK(tl); Fb(tl, 1, "%s0);\n", vp->lname); vcc_NextToken(tl); }
static void parse_unset(struct vcc *tl) { const struct var *vp; vcc_NextToken(tl); ExpectErr(tl, ID); vp = vcc_FindVar(tl, tl->t, 1, "cannot be unset"); ERRCHK(tl); assert(vp != NULL); if (vp->fmt != STRING || vp->http == NULL) { VSB_printf(tl->sb, "Only http header variables can be unset.\n"); vcc_ErrWhere(tl, tl->t); return; } ERRCHK(tl); Fb(tl, 1, "%s0);\n", vp->lname); vcc_NextToken(tl); }
static void parse_unset(struct vcc *tl) { const struct var *vp; /* XXX: Wrong, should use VCC_Expr(HEADER) */ vcc_NextToken(tl); ExpectErr(tl, ID); vp = vcc_FindVar(tl, tl->t, 1, "cannot be unset"); ERRCHK(tl); assert(vp != NULL); if (vp->fmt != HEADER) { VSB_printf(tl->sb, "Only HTTP header variables can be unset.\n"); vcc_ErrWhere(tl, tl->t); return; } ERRCHK(tl); Fb(tl, 1, "%svrt_magic_string_unset);\n", vp->lname); vcc_NextToken(tl); }
static void parse_unset(struct vcc *tl) { const struct symbol *sym; /* XXX: Wrong, should use VCC_Expr(HEADER) */ vcc_NextToken(tl); ExpectErr(tl, ID); sym = vcc_FindVar(tl, tl->t, 1, "cannot be unset"); ERRCHK(tl); assert(sym != NULL); if (sym->fmt != HEADER && !vcc_IdIs(tl->t, "bereq.body")) { VSB_printf(tl->sb, "Only bereq.body and HTTP header variables can" " be unset.\n"); vcc_ErrWhere(tl, tl->t); return; } ERRCHK(tl); Fb(tl, 1, "%svrt_magic_string_unset);\n", sym->lname); vcc_NextToken(tl); }
static void parse_return_vcl(struct vcc *tl) { struct symbol *sym; struct inifin *p; char buf[1024]; ExpectErr(tl, '('); vcc_NextToken(tl); ExpectErr(tl, ID); sym = VCC_SymbolTok(tl, NULL, tl->t, SYM_VCL, 0); ERRCHK(tl); if (sym == NULL) { VSB_printf(tl->sb, "Not a VCL label:\n"); vcc_ErrWhere(tl, tl->t); return; } if (sym->eval_priv == NULL) { VSB_printf(tl->fi, "%s VCL %.*s */\n", VCC_INFO_PREFIX, PF(tl->t)); bprintf(buf, "vgc_vcl_%u", tl->unique++); sym->eval_priv = strdup(buf); AN(sym->eval_priv); Fh(tl, 0, "static VCL_VCL %s;", buf); Fh(tl, 0, "\t/* VCL %.*s */\n", PF(tl->t)); p = New_IniFin(tl); AN(p); VSB_printf(p->ini, "\t%s = VRT_vcl_lookup(\"%.*s\");", buf, PF(tl->t)); } Fb(tl, 1, "VRT_vcl_select(ctx, %s);\t/* %.*s */\n", (const char*)sym->eval_priv, PF(tl->t)); vcc_NextToken(tl); ExpectErr(tl, ')'); vcc_NextToken(tl); }
static void parse_return(struct vcc *tl) { int retval = 0; vcc_NextToken(tl); ExpectErr(tl, '('); vcc_NextToken(tl); ExpectErr(tl, ID); /* 'error' gets special handling, to allow optional status/response */ if (vcc_IdIs(tl->t, "synth")) { vcc_NextToken(tl); if (tl->t->tok == ')') { VSB_printf(tl->sb, "Syntax has changed, use:\n" "\treturn(synth(999));\n" "or\n" "\treturn(synth(999, \"Response text\"));\n"); vcc_ErrWhere(tl, tl->t); return; } ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_error(ctx,\n"); tl->indent += INDENT; vcc_Expr(tl, INT); ERRCHK(tl); Fb(tl, 1, ",\n"); if (tl->t->tok == ',') { vcc_NextToken(tl); vcc_Expr(tl, STRING); ERRCHK(tl); } else { Fb(tl, 1, "(const char*)0\n"); } tl->indent -= INDENT; ExpectErr(tl, ')'); vcc_NextToken(tl); Fb(tl, 1, ");\n"); Fb(tl, 1, "VRT_handling(ctx, VCL_RET_SYNTH);\n"); Fb(tl, 1, "return (1);\n"); vcc_ProcAction(tl->curproc, VCL_RET_SYNTH, tl->t); ExpectErr(tl, ')'); vcc_NextToken(tl); return; } #define VCL_RET_MAC(l, U, B) \ do { \ if (vcc_IdIs(tl->t, #l)) { \ Fb(tl, 1, "VRT_handling(ctx, VCL_RET_" #U ");\n"); \ Fb(tl, 1, "return (1);\n"); \ vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\ retval = 1; \ } \ } while (0); #include "tbl/vcl_returns.h" #undef VCL_RET_MAC if (!retval) { VSB_printf(tl->sb, "Expected return action name.\n"); vcc_ErrWhere(tl, tl->t); ERRCHK(tl); } vcc_NextToken(tl); ExpectErr(tl, ')'); vcc_NextToken(tl); }
static void vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname) { struct token *t_field; struct token *t_host = NULL; struct token *t_port = NULL; struct token *t_hosthdr = NULL; unsigned saint = UINT_MAX; struct fld_spec *fs; struct vsb *vsb; unsigned u; double t; Fh(tl, 1, "\n#define VGC_backend_%s %d\n", vgcname, tl->ndirector); fs = vcc_FldSpec(tl, "!host", "?port", "?host_header", "?connect_timeout", "?first_byte_timeout", "?between_bytes_timeout", "?probe", "?max_connections", "?saintmode_threshold", NULL); SkipToken(tl, '{'); vsb = VSB_new_auto(); AN(vsb); tl->fb = vsb; Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n", vgcname); Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir)); if (serial >= 0) Fb(tl, 0, "[%d]", serial); Fb(tl, 0, "\",\n"); /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { VSB_printf(tl->sb, "NB: Backend Syntax has changed:\n" "Remove \"set\" and \"backend\" in front" " of backend fields.\n" ); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at "); vcc_ErrWhere(tl, tl->t); return; } while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); ERRCHK(tl); if (vcc_IdIs(t_field, "host")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_host = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "port")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "host_header")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_hosthdr = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "connect_timeout")) { Fb(tl, 0, "\t.connect_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "first_byte_timeout")) { Fb(tl, 0, "\t.first_byte_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "between_bytes_timeout")) { Fb(tl, 0, "\t.between_bytes_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "max_connections")) { u = vcc_UintVal(tl); ERRCHK(tl); SkipToken(tl, ';'); Fb(tl, 0, "\t.max_connections = %u,\n", u); } else if (vcc_IdIs(t_field, "saintmode_threshold")) { u = vcc_UintVal(tl); /* UINT_MAX == magic number to mark as unset, so * not allowed here. */ if (u == UINT_MAX) { VSB_printf(tl->sb, "Value outside allowed range: "); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); } ERRCHK(tl); saint = u; SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { Fb(tl, 0, "\t.probe = &vgc_probe__%d,\n", tl->nprobe); vcc_ParseProbeSpec(tl); ERRCHK(tl); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) { Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t)); vcc_AddRef(tl, tl->t, SYM_PROBE); vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe")) { VSB_printf(tl->sb, "Expected '{' or name of probe."); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); return; } else { ErrInternal(tl); return; } } vcc_FieldsOk(tl, fs); ERRCHK(tl); /* Check that the hostname makes sense */ assert(t_host != NULL); if (t_port != NULL) Emit_Sockaddr(tl, t_host, t_port->dec); else Emit_Sockaddr(tl, t_host, "80"); ERRCHK(tl); ExpectErr(tl, '}'); /* We have parsed it all, emit the ident string */ /* Emit the hosthdr field, fall back to .host if not specified */ Fb(tl, 0, "\t.hosthdr = "); if (t_hosthdr != NULL) EncToken(tl->fb, t_hosthdr); else EncToken(tl->fb, t_host); Fb(tl, 0, ",\n"); Fb(tl, 0, "\t.saintmode_threshold = %d,\n",saint); /* Close the struct */ Fb(tl, 0, "};\n"); vcc_NextToken(tl); tl->fb = NULL; AZ(VSB_finish(vsb)); Fh(tl, 0, "%s", VSB_data(vsb)); VSB_delete(vsb); Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"simple\",\n" "\t VGC_backend_%s, &vgc_dir_priv_%s);\n", vgcname, vgcname); Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname); tl->ndirector++; }
static void parse_purge(struct tokenlist *tl) { const struct purge_var *pv; vcc_NextToken(tl); ExpectErr(tl, '('); vcc_NextToken(tl); if (tl->t->tok == VAR) { Fb(tl, 1, "VRT_ban(sp,\n"); tl->indent += INDENT; while (1) { ExpectErr(tl, VAR); /* Check valididity of purge variable */ for (pv = purge_var; pv->name != NULL; pv++) { if (!strncmp(pv->name, tl->t->b, strlen(pv->name))) break; } if (pv->name == NULL) { vsb_printf(tl->sb, "Unknown purge variable."); vcc_ErrWhere(tl, tl->t); return; } if ((pv->flag & PVAR_HTTP) && tl->t->b + strlen(pv->name) >= tl->t->e) { vsb_printf(tl->sb, "Missing header name."); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); vcc_NextToken(tl); switch(tl->t->tok) { case '~': case T_NOMATCH: case T_EQ: case T_NEQ: Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); break; default: vsb_printf(tl->sb, "Expected ~, !~, == or !=.\n"); vcc_ErrWhere(tl, tl->t); return; } vcc_NextToken(tl); Fb(tl, 1, " "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } Fb(tl, 0, ",\n"); if (tl->t->tok == ')') break; ExpectErr(tl, T_CAND); Fb(tl, 1, "\"%.*s\",\n", PF(tl->t)); vcc_NextToken(tl); } Fb(tl, 1, "0);\n"); tl->indent -= INDENT; } else { Fb(tl, 1, "VRT_ban_string(sp, "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); Fb(tl, 0, "vrt_magic_string_end);\n"); } ExpectErr(tl, ')'); vcc_NextToken(tl); }
static void parse_set(struct tokenlist *tl) { struct var *vp; struct token *at, *vt; vcc_NextToken(tl); ExpectErr(tl, VAR); vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); check_writebit(tl, vp); ERRCHK(tl); Fb(tl, 1, "%s", vp->lname); vcc_NextToken(tl); switch (vp->fmt) { case INT: case SIZE: case TIME: case RTIME: case FLOAT: if (tl->t->tok != '=') Fb(tl, 0, "%s %c ", vp->rname, *tl->t->b); at = tl->t; vcc_NextToken(tl); switch (at->tok) { case T_MUL: case T_DIV: Fb(tl, 0, "%g", vcc_DoubleVal(tl)); break; case T_INCR: case T_DECR: case '=': vcc_VarVal(tl, vp, vt); ERRCHK(tl); break; default: vsb_printf(tl->sb, "Invalid assignment operator.\n"); vcc_ErrWhere(tl, at); return; } Fb(tl, 0, ");\n"); break; #if 0 /* XXX: enable if we find a legit use */ case IP: if (tl->t->tok != '=') { illegal_assignment(tl, "IP numbers"); return; } vcc_NextToken(tl); u = vcc_vcc_IpVal(tl); Fb(tl, 0, "= %uU; /* %u.%u.%u.%u */\n", u, (u >> 24) & 0xff, (u >> 16) & 0xff, (u >> 8) & 0xff, u & 0xff); break; #endif case BACKEND: if (tl->t->tok != '=') { illegal_assignment(tl, "backend"); return; } vcc_NextToken(tl); vcc_ExpectCid(tl); ERRCHK(tl); vcc_AddRef(tl, tl->t, R_BACKEND); Fb(tl, 0, "VGCDIR(_%.*s)", PF(tl->t)); vcc_NextToken(tl); Fb(tl, 0, ");\n"); break; case HASH: SkipToken(tl, T_INCR); if (!vcc_StringVal(tl)) { ERRCHK(tl); vcc_ExpectedStringval(tl); return; } Fb(tl, 0, ");\n"); /* * We count the number of operations on the req.hash * variable, so that varnishd can preallocate the worst case * number of slots for composing the hash string. */ break; case STRING: if (tl->t->tok != '=') { illegal_assignment(tl, "strings"); return; } vcc_NextToken(tl); if (!vcc_StringVal(tl)) { ERRCHK(tl); vcc_ExpectedStringval(tl); return; } do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); if (tl->t->tok != ';') { ERRCHK(tl); vsb_printf(tl->sb, "Expected variable, string or semicolon\n"); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 0, "vrt_magic_string_end);\n"); break; case BOOL: if (tl->t->tok != '=') { illegal_assignment(tl, "boolean"); return; } vcc_NextToken(tl); ExpectErr(tl, ID); if (vcc_IdIs(tl->t, "true")) { Fb(tl, 0, " 1);\n", vp->lname); } else if (vcc_IdIs(tl->t, "false")) { Fb(tl, 0, " 0);\n", vp->lname); } else { vsb_printf(tl->sb, "Expected true or false\n"); vcc_ErrWhere(tl, tl->t); return; } vcc_NextToken(tl); break; default: vsb_printf(tl->sb, "Assignments not possible for type of '%s'\n", vp->name); vcc_ErrWhere(tl, tl->t); return; } }
void test_solver(BfmSolver solver,LatticeFermion &src) { g5dParams parms; int Ls=8; double M5=1.8; double mq=0.01; double wilson_lo = 0.05; double wilson_hi = 6.8; double shamir_lo = 0.025; double shamir_hi = 1.7; double ht_scale=2.0; double hw_scale=1.0; if ( solver == HtCayleyTanh ) { Printf("Testing HtCayleyTanh aka DWF\n"); parms.ShamirCayleyTanh(mq,M5,Ls); } else if ( solver == HmCayleyTanh ) { parms.ScaledShamirCayleyTanh(mq,M5,Ls,ht_scale); Printf("Testing HmCayleyTanh Moebius\n"); } else if ( solver == HwCayleyTanh ) { parms.WilsonCayleyTanh(mq,M5,Ls,hw_scale); Printf("Testing HwCayleyTanh aka Borici\n"); } else { exit(-1); } multi1d<LatticeColorMatrix> u(4); HotSt(u); multi1d<LatticeFermion> X(Ls); multi1d<LatticeFermion> Y(Ls); for(int s=0;s<Ls;s++){ gaussian(X[s]); gaussian(Y[s]); } multi1d<LatticeColorMatrix> Fb(4); multi1d<LatticeColorMatrix> F (4); int lx = QDP::Layout::subgridLattSize()[0]; int ly = QDP::Layout::subgridLattSize()[1]; int lz = QDP::Layout::subgridLattSize()[2]; int lt = QDP::Layout::subgridLattSize()[3]; multi1d<int> procs = QDP::Layout::logicalSize(); /******************************************************** * Setup DWF operator ******************************************************** */ bfmarg dwfa; dwfa.node_latt[0] = lx; dwfa.node_latt[1] = ly; dwfa.node_latt[2] = lz; dwfa.node_latt[3] = lt; for(int mu=0;mu<4;mu++){ if ( procs[mu]>1 ) { dwfa.local_comm[mu] = 0; } else { dwfa.local_comm[mu] = 1; } } bfm_qmp dwf_qmp; dwfa.mass = parms.mass; dwfa.M5 = parms.M5; dwfa.Csw = 0.0; dwfa.precon_5d=0; dwfa.residual=1.0e-5; dwfa.max_iter=5000; dwfa.Ls = parms.Ls; dwfa.solver= parms.solver; dwfa.zolo_lo = parms.zolo_lo; dwfa.zolo_hi = parms.zolo_hi; dwfa.mobius_scale = parms.mobius_scale; dwf_qmp.init(dwfa); dwf_qmp.importGauge(u); Fermion_t X_t; Fermion_t Y_t; Matrix_t Force_t[2]; X_t = dwf_qmp.allocFermion(); Y_t = dwf_qmp.allocFermion(); for(int cb=0;cb<2;cb++){ Force_t[cb] = dwf_qmp.allocMatrix(); printf("Force_t pointer %lx\n",Force_t[cb]); } multi1d<int> bcs(Nd); bcs[0] = bcs[1] = bcs[2] = bcs[3] = 1; Handle<FermBC<T,U,U> > fbc(new SimpleFermBC< T, U, U >(bcs)); Handle<CreateFermState<T,U,U> > cfs( new CreateSimpleFermState<T,U,U>(fbc)); Handle<FermState<T,U,U> > fs ((*cfs)(u)); //! Params for NEFF EvenOddPrecKNOFermActArrayParams kparams; Real scale = dwf_qmp.mobius_scale; kparams.OverMass = dwf_qmp.M5; kparams.Mass = dwf_qmp.mass; kparams.a5 = 1.0; kparams.coefs.resize(Ls); for(int s=0;s<Ls;s++) kparams.coefs[s] = scale; kparams.N5 = dwf_qmp.Ls; EvenOddPrecKNOFermActArray FA(cfs,kparams); Handle< DiffLinearOperatorArray<Phi,P,Q> > M(FA.linOp(fs)); for( int dag=0;dag<2;dag++){ Fb=zero; F=zero; dwf_qmp.importFermion(X,X_t,1); dwf_qmp.importFermion(Y,Y_t,1); dwf_qmp.zeroMatrix(Force_t[0]); dwf_qmp.zeroMatrix(Force_t[1]); dwf_qmp.MprecDeriv(X_t,Y_t,Force_t,dag); for(int cb=0;cb<2;cb++) dwf_qmp.exportForce(Force_t[cb],Fb,cb); Printf("Calling S_f deriv\n"); if( dag==1 ) M->deriv(F, X, Y, MINUS); else M->deriv(F, X, Y, PLUS); for(int mu=0;mu<4;mu++){ QDPIO::cout << "dag "<< dag<<"mu "<<mu<<" n2diff " << norm2(Fb[mu]-F[mu])<<endl; } #if 0 QDPIO::cout << "Calling force term" << endl; dwf_qmp.zeroMatrix(Force_t[0]); dwf_qmp.zeroMatrix(Force_t[1]); dwf_qmp.TwoFlavorRatioForce(X_t,Force_t,1.0,dwf_qmp.mass); for(int cb=0;cb<2;cb++) dwf_qmp.exportForce(Force_t[cb],Fb,cb); for(int mu=0;mu<4;mu++){ QDPIO::cout << "dag "<< dag<<"mu "<<mu<<" TwoFlavorForce " << norm2(Fb[mu])<<endl; } #endif // { // EvenOddPrecConstDetTwoFlavorRatioConvConvWilsonTypeFermMonomial5D Monomial(); // } } dwf_qmp.freeMatrix(Force_t[0]); dwf_qmp.freeMatrix(Force_t[1]); exit(0); }
static void vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname) { struct token *t_field; struct token *t_val; struct token *t_host = NULL; struct token *t_port = NULL; struct token *t_path = NULL; struct token *t_hosthdr = NULL; struct symbol *pb; struct token *t_did = NULL; struct fld_spec *fs; struct inifin *ifp; struct vsb *vsb; char *p; unsigned u; double t; fs = vcc_FldSpec(tl, "?host", "?port", "?path", "?host_header", "?connect_timeout", "?first_byte_timeout", "?between_bytes_timeout", "?probe", "?max_connections", "?proxy_header", NULL); SkipToken(tl, '{'); vsb = VSB_new_auto(); AN(vsb); tl->fb = vsb; Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n", vgcname); Fb(tl, 0, "\t.magic = VRT_BACKEND_MAGIC,\n"); Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(t_be)); Fb(tl, 0, "\",\n"); /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { VSB_printf(tl->sb, "NB: Backend Syntax has changed:\n" "Remove \"set\" and \"backend\" in front" " of backend fields.\n" ); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at "); vcc_ErrWhere(tl, tl->t); return; } while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); ERRCHK(tl); if (vcc_IdIs(t_field, "host")) { vcc_Redef(tl, "Address", &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_host = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "port")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "path")) { if (tl->syntax < VCL_41) { VSB_printf(tl->sb, "Unix socket backends only supported" " in VCL4.1 and higher.\n"); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at "); vcc_ErrWhere(tl, tl->t); return; } vcc_Redef(tl, "Address", &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_path = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "host_header")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_hosthdr = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "connect_timeout")) { Fb(tl, 0, "\t.connect_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "first_byte_timeout")) { Fb(tl, 0, "\t.first_byte_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "between_bytes_timeout")) { Fb(tl, 0, "\t.between_bytes_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "max_connections")) { u = vcc_UintVal(tl); ERRCHK(tl); SkipToken(tl, ';'); Fb(tl, 0, "\t.max_connections = %u,\n", u); } else if (vcc_IdIs(t_field, "proxy_header")) { t_val = tl->t; u = vcc_UintVal(tl); ERRCHK(tl); if (u != 1 && u != 2) { VSB_printf(tl->sb, ".proxy_header must be 1 or 2\n"); vcc_ErrWhere(tl, t_val); return; } SkipToken(tl, ';'); Fb(tl, 0, "\t.proxy_header = %u,\n", u); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { vcc_ParseProbeSpec(tl, NULL, &p); Fb(tl, 0, "\t.probe = %s,\n", p); ERRCHK(tl); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) { if (vcc_IdIs(tl->t, "default")) { vcc_NextToken(tl); (void)vcc_default_probe(tl); } else { pb = VCC_SymbolGet(tl, SYM_PROBE, "Probe not found", XREF_REF); ERRCHK(tl); AN(pb); Fb(tl, 0, "\t.probe = %s,\n", pb->rname); } SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe")) { VSB_printf(tl->sb, "Expected '{' or name of probe, got "); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); return; } else { ErrInternal(tl); return; } } vcc_FieldsOk(tl, fs); ERRCHK(tl); if (t_host == NULL && t_path == NULL) { VSB_printf(tl->sb, "Expected .host or .path.\n"); vcc_ErrWhere(tl, t_be); return; } assert(t_host != NULL || t_path != NULL); if (t_host != NULL) /* Check that the hostname makes sense */ Emit_Sockaddr(tl, t_host, t_port); else /* Check that the path can be a legal UDS */ Emit_UDS_Path(tl, t_path, "Backend path"); ERRCHK(tl); ExpectErr(tl, '}'); /* We have parsed it all, emit the ident string */ /* Emit the hosthdr field, fall back to .host if not specified */ /* If .path is specified, set "0.0.0.0". */ Fb(tl, 0, "\t.hosthdr = "); if (t_hosthdr != NULL) EncToken(tl->fb, t_hosthdr); else if (t_host != NULL) EncToken(tl->fb, t_host); else Fb(tl, 0, "\"0.0.0.0\""); Fb(tl, 0, ",\n"); /* Close the struct */ Fb(tl, 0, "};\n"); vcc_NextToken(tl); tl->fb = NULL; AZ(VSB_finish(vsb)); Fh(tl, 0, "%s", VSB_data(vsb)); VSB_destroy(&vsb); ifp = New_IniFin(tl); VSB_printf(ifp->ini, "\t%s =\n\t VRT_new_backend_clustered(ctx, vsc_cluster,\n" "\t\t&vgc_dir_priv_%s);", vgcname, vgcname); VSB_printf(ifp->fin, "\t\tVRT_delete_backend(ctx, &%s);", vgcname); }
static void vcc_ParseFunction(struct vcc *tl) { int m, i; vcc_NextToken(tl); vcc_ExpectCid(tl, "function"); ERRCHK(tl); m = IsMethod(tl->t); if (m == -2) { VSB_printf(tl->sb, "VCL sub's named 'vcl*' are reserved names.\n"); vcc_ErrWhere(tl, tl->t); VSB_printf(tl->sb, "Valid vcl_* methods are:\n"); for (i = 1; method_tab[i].name != NULL; i++) VSB_printf(tl->sb, "\t%s\n", method_tab[i].name); return; } else if (m != -1) { assert(m < VCL_MET_MAX); tl->fb = tl->fm[m]; if (tl->mprocs[m] == NULL) { (void)vcc_AddDef(tl, tl->t, SYM_SUB); vcc_AddRef(tl, tl->t, SYM_SUB); tl->mprocs[m] = vcc_AddProc(tl, tl->t); } tl->curproc = tl->mprocs[m]; Fb(tl, 1, " /* ... from "); vcc_Coord(tl, tl->fb, NULL); Fb(tl, 0, " */\n"); } else { tl->fb = tl->fc; i = vcc_AddDef(tl, tl->t, SYM_SUB); if (i > 1) { VSB_printf(tl->sb, "Function '%.*s' redefined\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); return; } tl->curproc = vcc_AddProc(tl, tl->t); Fh(tl, 0, "int VGC_function_%.*s " "(VRT_CTX);\n", PF(tl->t)); Fc(tl, 1, "\nint __match_proto__(vcl_func_t)\n"); Fc(tl, 1, "VGC_function_%.*s(VRT_CTX)\n", PF(tl->t)); } vcc_NextToken(tl); tl->indent += INDENT; Fb(tl, 1, "{\n"); L(tl, vcc_Compound(tl)); if (m == -1) { /* * non-method subroutines must have an explicit non-action * return in case they just fall through the bottom. */ Fb(tl, 1, " return(0);\n"); } Fb(tl, 1, "}\n"); tl->indent -= INDENT; tl->fb = NULL; tl->curproc = NULL; }
static void Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) { struct foo_proto protos[3], *pp; struct addrinfo *res, *res0, *res1, hint; int error, retval, x; char hbuf[NI_MAXHOST]; char *hop, *pop; AN(t_host->dec); memset(protos, 0, sizeof protos); protos[0].name = "ipv4"; protos[0].family = PF_INET; protos[1].name = "ipv6"; protos[1].family = PF_INET6; retval = 0; memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; if (VSS_parse(t_host->dec, &hop, &pop)) { VSB_printf(tl->sb, "Backend host '%.*s': wrong syntax (unbalanced [...] ?)\n", PF(t_host) ); vcc_ErrWhere(tl, t_host); return; } error = getaddrinfo( hop != NULL ? hop : t_host->dec, pop != NULL ? pop : port, &hint, &res0); free(hop); free(pop); if (error) { VSB_printf(tl->sb, "Backend host '%.*s'" " could not be resolved to an IP address:\n", PF(t_host)); VSB_printf(tl->sb, "\t%s\n" "(Sorry if that error message is gibberish.)\n", gai_strerror(error)); vcc_ErrWhere(tl, t_host); return; } for (res = res0; res; res = res->ai_next) { for (pp = protos; pp->name != NULL; pp++) if (res->ai_family == pp->family) break; if (pp->name == NULL) { /* Unknown proto, ignore */ continue; } if (pp->l == res->ai_addrlen && !memcmp(&pp->sa, res->ai_addr, pp->l)) { /* * Same address we already emitted. * This can happen using /etc/hosts */ continue; } if (pp->l > 0) { VSB_printf(tl->sb, "Backend host %.*s: resolves to " "multiple %s addresses.\n" "Only one address is allowed.\n" "Please specify which exact address " "you want to use, we found these:\n", PF(t_host), pp->name); for (res1 = res0; res1 != NULL; res1 = res1->ai_next) { error = getnameinfo(res1->ai_addr, res1->ai_addrlen, hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST); AZ(error); VSB_printf(tl->sb, "\t%s\n", hbuf); } freeaddrinfo(res0); vcc_ErrWhere(tl, t_host); return; } pp->l = res->ai_addrlen; memcpy(&pp->sa, res->ai_addr, pp->l); x = emit_sockaddr(tl, res->ai_addr, res->ai_addrlen); Fb(tl, 0, "\t.%s_sockaddr = sockaddr_%u,\n", pp->name, x); error = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST); AZ(error); Fb(tl, 0, "\t.%s_addr = \"%s\",\n", pp->name, hbuf); retval++; } if (res0 != NULL) { error = getnameinfo(res0->ai_addr, res0->ai_addrlen, NULL, 0, hbuf, sizeof hbuf, NI_NUMERICSERV); AZ(error); Fb(tl, 0, "\t.port = \"%s\",\n", hbuf); } freeaddrinfo(res0); if (retval == 0) { VSB_printf(tl->sb, "Backend host '%.*s': resolves to " "neither IPv4 nor IPv6 addresses.\n", PF(t_host) ); vcc_ErrWhere(tl, t_host); } }
static void vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname) { struct token *t_field; struct token *t_val; struct token *t_host = NULL; struct token *t_port = NULL; struct token *t_hosthdr = NULL; struct fld_spec *fs; struct inifin *ifp; struct vsb *vsb; char *p; unsigned u; double t; fs = vcc_FldSpec(tl, "!host", "?port", "?host_header", "?connect_timeout", "?first_byte_timeout", "?between_bytes_timeout", "?probe", "?max_connections", "?proxy_header", NULL); SkipToken(tl, '{'); vsb = VSB_new_auto(); AN(vsb); tl->fb = vsb; Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n", vgcname); Fb(tl, 0, "\t.magic = VRT_BACKEND_MAGIC,\n"); Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(t_be)); Fb(tl, 0, "\",\n"); /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { VSB_printf(tl->sb, "NB: Backend Syntax has changed:\n" "Remove \"set\" and \"backend\" in front" " of backend fields.\n" ); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at "); vcc_ErrWhere(tl, tl->t); return; } while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); ERRCHK(tl); if (vcc_IdIs(t_field, "host")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_host = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "port")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "host_header")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_hosthdr = tl->t; vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "connect_timeout")) { Fb(tl, 0, "\t.connect_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "first_byte_timeout")) { Fb(tl, 0, "\t.first_byte_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "between_bytes_timeout")) { Fb(tl, 0, "\t.between_bytes_timeout = "); vcc_Duration(tl, &t); ERRCHK(tl); Fb(tl, 0, "%g,\n", t); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "max_connections")) { u = vcc_UintVal(tl); ERRCHK(tl); SkipToken(tl, ';'); Fb(tl, 0, "\t.max_connections = %u,\n", u); } else if (vcc_IdIs(t_field, "proxy_header")) { t_val = tl->t; u = vcc_UintVal(tl); ERRCHK(tl); if (u != 1 && u != 2) { VSB_printf(tl->sb, ".proxy_header must be 1 or 2\n"); vcc_ErrWhere(tl, t_val); return; } SkipToken(tl, ';'); Fb(tl, 0, "\t.proxy_header = %u,\n", u); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { vcc_ParseProbeSpec(tl, NULL, &p); Fb(tl, 0, "\t.probe = &%s,\n", p); ERRCHK(tl); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) { if (VCC_FindSymbol(tl, tl->t, SYM_PROBE) == NULL) { VSB_printf(tl->sb, "Probe %.*s not found\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t)); vcc_AddRef(tl, tl->t, SYM_PROBE); vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe")) { VSB_printf(tl->sb, "Expected '{' or name of probe, got "); vcc_ErrToken(tl, tl->t); VSB_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); return; } else { ErrInternal(tl); return; } } vcc_FieldsOk(tl, fs); ERRCHK(tl); /* Check that the hostname makes sense */ assert(t_host != NULL); Emit_Sockaddr(tl, t_host, t_port); ERRCHK(tl); ExpectErr(tl, '}'); /* We have parsed it all, emit the ident string */ /* Emit the hosthdr field, fall back to .host if not specified */ Fb(tl, 0, "\t.hosthdr = "); if (t_hosthdr != NULL) EncToken(tl->fb, t_hosthdr); else EncToken(tl->fb, t_host); Fb(tl, 0, ",\n"); /* Close the struct */ Fb(tl, 0, "};\n"); vcc_NextToken(tl); tl->fb = NULL; AZ(VSB_finish(vsb)); Fh(tl, 0, "%s", VSB_data(vsb)); VSB_destroy(&vsb); ifp = New_IniFin(tl); VSB_printf(ifp->ini, "\t%s =\n\t VRT_new_backend(ctx, &vgc_dir_priv_%s);", vgcname, vgcname); }
int PFEMElement2D::update() { // get nodal coordinates double x[3], y[3]; for(int a=0; a<3; a++) { const Vector& coord = nodes[2*a]->getCrds(); const Vector& disp = nodes[2*a]->getTrialDisp(); x[a] = coord(0) + disp(0); y[a] = coord(1) + disp(1); } // get c and d double cc[3], dd[3]; cc[0] = y[1]-y[2]; dd[0] = x[2]-x[1]; cc[1] = y[2]-y[0]; dd[1] = x[0]-x[2]; cc[2] = y[0]-y[1]; dd[2] = x[1]-x[0]; // get Jacobi double J = cc[0]*dd[1]-dd[0]*cc[1]; if(fabs(J)<1e-15) { opserr<<"WARNING: element area is nearly zero"; opserr<<" -- PFEMElement2D::update\n"; for (int i=0; i<3; i++) { opserr<<"node "<<ntags[2*i]<<"\n"; opserr<<"x = "<<x[i]<<" , y = "<<y[i]<<"\n"; } return -1; } // get M M = rho*J*thickness/6.0; Mp = (kappa<=0? 0.0 : J*thickness/kappa/24.0); double Mb = 9.*rho*J*thickness/40.0; // get Km Km.Zero(); double fact = mu*thickness/(6.*J); for (int a=0; a<3; a++) { for (int b=0; b<3; b++) { Km(2*a,2*b) = fact*(4*cc[a]*cc[b]+3*dd[a]*dd[b]); // Kxx Km(2*a,2*b+1) = fact*(3*dd[a]*cc[b]-2*cc[a]*dd[b]); // Kxy Km(2*a+1,2*b) = fact*(3*cc[a]*dd[b]-2*dd[a]*cc[b]); // Kyx Km(2*a+1,2*b+1) = fact*(3*cc[a]*cc[b]+4*dd[a]*dd[b]); // Kyy } } // get Kb Matrix Kb(2,2); fact = 27.*mu*thickness/(40.*J); double cc2 = 0., dd2 = 0., cd2 = 0.; for(int a=0; a<3; a++) { cc2 += cc[a]*cc[a]; dd2 += dd[a]*dd[a]; cd2 += cc[a]*dd[a]; } Kb(0,0) = fact*(4*cc2+3*dd2); // Kxx Kb(0,1) = fact*cd2; // Kxy Kb(1,0) = fact*cd2; // Kyx Kb(1,1) = fact*(3*cc2+4*dd2); // Kyy // get Gx and Gy Gx.Zero(); Gy.Zero(); fact = thickness/6.0; for (int a=0; a<3; a++) { Gx(a) = cc[a]*fact; Gy(a) = dd[a]*fact; } // get Gb Matrix Gb(2,3); fact = -9.*thickness/40.0; for (int a=0; a<3; a++) { Gb(0,a) = cc[a]*fact; Gb(1,a) = dd[a]*fact; } // get S S.Zero(); if (ops_Dt > 0) { Kb(0,0) += Mb/ops_Dt; Kb(1,1) += Mb/ops_Dt; } if (Kb(0,0)!=0 && Kb(1,1)!=0) { this->inverse(Kb); } S.addMatrixTripleProduct(0.0, Gb, Kb, 1); // get F F.Zero(); fact = rho*J*thickness/6.0; F(0) = fact*b1; F(1) = fact*b2; // get Fb Vector Fb(2); fact = 9.*rho*J*thickness/40.; Fb(0) = fact*b1; Fb(1) = fact*b2; // get Fp Fp.Zero(); Fp.addMatrixTransposeVector(0.0, Gb, Kb*Fb, -1); return 0; }
// The matrix assembly function to be called at each time step to // prepare for the linear solve. void assemble_solid (EquationSystems& es, const std::string& system_name) { //es.print_info(); #if LOG_ASSEMBLE_PERFORMANCE PerfLog perf_log("Assemble"); perf_log.push("assemble stiffness"); #endif // Get a reference to the auxiliary system //TransientExplicitSystem& aux_system = es.get_system<TransientExplicitSystem>("Newton-update"); // It is a good idea to make sure we are assembling // the proper system. libmesh_assert (system_name == "Newton-update"); // Get a constant reference to the mesh object. const MeshBase& mesh = es.get_mesh(); // The dimension that we are running const unsigned int dim = mesh.mesh_dimension(); // Get a reference to the Stokes system object. TransientLinearImplicitSystem & newton_update = es.get_system<TransientLinearImplicitSystem> ("Newton-update"); // New TransientLinearImplicitSystem & last_non_linear_soln = es.get_system<TransientLinearImplicitSystem> ("Last-non-linear-soln"); TransientLinearImplicitSystem & fluid_system_vel = es.get_system<TransientLinearImplicitSystem> ("fluid-system-vel"); #if VELOCITY TransientLinearImplicitSystem& velocity = es.get_system<TransientLinearImplicitSystem>("velocity-system"); #endif #if UN_MINUS_ONE TransientLinearImplicitSystem & unm1 = es.get_system<TransientLinearImplicitSystem> ("unm1-system"); #endif test(62); const System & ref_sys = es.get_system("Reference-Configuration"); test(63); // Numeric ids corresponding to each variable in the system const unsigned int u_var = last_non_linear_soln .variable_number ("u"); const unsigned int v_var = last_non_linear_soln .variable_number ("v"); const unsigned int w_var = last_non_linear_soln .variable_number ("w"); #if INCOMPRESSIBLE const unsigned int p_var = last_non_linear_soln .variable_number ("p"); #endif #if FLUID_P_CONST const unsigned int m_var = fluid_system_vel.variable_number ("fluid_M"); std::vector<unsigned int> dof_indices_m; #endif // Get the Finite Element type for "u". Note this will be // the same as the type for "v". FEType fe_vel_type = last_non_linear_soln.variable_type(u_var); test(64); #if INCOMPRESSIBLE // Get the Finite Element type for "p". FEType fe_pres_type = last_non_linear_soln .variable_type(p_var); #endif // Build a Finite Element object of the specified type for // the velocity variables. AutoPtr<FEBase> fe_vel (FEBase::build(dim, fe_vel_type)); #if INCOMPRESSIBLE // Build a Finite Element object of the specified type for // the pressure variables. AutoPtr<FEBase> fe_pres (FEBase::build(dim, fe_pres_type)); #endif // A Gauss quadrature rule for numerical integration. // Let the \p FEType object decide what order rule is appropriate. QGauss qrule (dim, fe_vel_type.default_quadrature_order()); // Tell the finite element objects to use our quadrature rule. fe_vel->attach_quadrature_rule (&qrule); test(65); // AutoPtr<QBase> qrule2(fe_vel_type.default_quadrature_rule(dim)); // fe_vel->attach_quadrature_rule (qrule2.get()); #if INCOMPRESSIBLE fe_pres->attach_quadrature_rule (&qrule); #endif // The element Jacobian * quadrature weight at each integration point. const std::vector<Real>& JxW = fe_vel->get_JxW(); // The element shape functions evaluated at the quadrature points. const std::vector<std::vector<Real> >& phi = fe_vel->get_phi(); // The element shape function gradients for the velocity // variables evaluated at the quadrature points. const std::vector<std::vector<RealGradient> >& dphi = fe_vel->get_dphi(); test(66); #if INCOMPRESSIBLE // The element shape functions for the pressure variable // evaluated at the quadrature points. const std::vector<std::vector<Real> >& psi = fe_pres->get_phi(); #endif const std::vector<Point>& coords = fe_vel->get_xyz(); // A reference to the \p DofMap object for this system. The \p DofMap // object handles the index translation from node and element numbers // to degree of freedom numbers. We will talk more about the \p DofMap // in future examples. const DofMap & dof_map = last_non_linear_soln .get_dof_map(); #if FLUID_P_CONST const DofMap & dof_map_fluid = fluid_system_vel .get_dof_map(); #endif // K will be the jacobian // F will be the Residual DenseMatrix<Number> Ke; DenseVector<Number> Fe; DenseSubMatrix<Number> Kuu(Ke), Kuv(Ke), Kuw(Ke), Kvu(Ke), Kvv(Ke), Kvw(Ke), Kwu(Ke), Kwv(Ke), Kww(Ke); #if INCOMPRESSIBLE DenseSubMatrix<Number> Kup(Ke),Kvp(Ke),Kwp(Ke), Kpu(Ke), Kpv(Ke), Kpw(Ke), Kpp(Ke); #endif; DenseSubVector<Number> Fu(Fe), Fv(Fe), Fw(Fe); #if INCOMPRESSIBLE DenseSubVector<Number> Fp(Fe); #endif // This vector will hold the degree of freedom indices for // the element. These define where in the global system // the element degrees of freedom get mapped. std::vector<unsigned int> dof_indices; std::vector<unsigned int> dof_indices_u; std::vector<unsigned int> dof_indices_v; std::vector<unsigned int> dof_indices_w; #if INCOMPRESSIBLE std::vector<unsigned int> dof_indices_p; #endif #if INERTIA test(67); const unsigned int a_var = last_non_linear_soln.variable_number ("a"); const unsigned int b_var = last_non_linear_soln.variable_number ("b"); const unsigned int c_var = last_non_linear_soln.variable_number ("c"); //B block DenseSubMatrix<Number> Kua(Ke), Kub(Ke), Kuc(Ke), Kva(Ke), Kvb(Ke), Kvc(Ke), Kwa(Ke), Kwb(Ke), Kwc(Ke); //C block DenseSubMatrix<Number> Kau(Ke), Kav(Ke), Kaw(Ke), Kbu(Ke), Kbv(Ke), Kbw(Ke), Kcu(Ke), Kcv(Ke), Kcw(Ke); //D block DenseSubMatrix<Number> Kaa(Ke), Kab(Ke), Kac(Ke), Kba(Ke), Kbb(Ke), Kbc(Ke), Kca(Ke), Kcb(Ke), Kcc(Ke); DenseSubVector<Number> Fa(Fe), Fb(Fe), Fc(Fe); std::vector<unsigned int> dof_indices_a; std::vector<unsigned int> dof_indices_b; std::vector<unsigned int> dof_indices_c; test(68); #endif DenseMatrix<Real> stiff; DenseVector<Real> res; VectorValue<Gradient> grad_u_mat; VectorValue<Gradient> grad_u_mat_old; const Real dt = es.parameters.get<Real>("dt"); const Real progress = es.parameters.get<Real>("progress"); #if PORO DenseVector<Real> p_stiff; DenseVector<Real> p_res; PoroelasticConfig material(dphi,psi); #endif // Just calculate jacobian contribution when we need to material.calculate_linearized_stiffness = true; MeshBase::const_element_iterator el = mesh.active_local_elements_begin(); const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end(); for ( ; el != end_el; ++el) { test(69); const Elem* elem = *el; dof_map.dof_indices (elem, dof_indices); dof_map.dof_indices (elem, dof_indices_u, u_var); dof_map.dof_indices (elem, dof_indices_v, v_var); dof_map.dof_indices (elem, dof_indices_w, w_var); #if INCOMPRESSIBLE dof_map.dof_indices (elem, dof_indices_p, p_var); #endif const unsigned int n_dofs = dof_indices.size(); const unsigned int n_u_dofs = dof_indices_u.size(); const unsigned int n_v_dofs = dof_indices_v.size(); const unsigned int n_w_dofs = dof_indices_w.size(); #if INCOMPRESSIBLE const unsigned int n_p_dofs = dof_indices_p.size(); #endif #if FLUID_P_CONST dof_map_fluid.dof_indices (elem, dof_indices_m, m_var); #endif //elem->print_info(); fe_vel->reinit (elem); #if INCOMPRESSIBLE fe_pres->reinit (elem); #endif Ke.resize (n_dofs, n_dofs); Fe.resize (n_dofs); Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs); Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs); Kuw.reposition (u_var*n_u_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs); #if INCOMPRESSIBLE Kup.reposition (u_var*n_u_dofs, p_var*n_u_dofs, n_u_dofs, n_p_dofs); #endif Kvu.reposition (v_var*n_v_dofs, u_var*n_v_dofs, n_v_dofs, n_u_dofs); Kvv.reposition (v_var*n_v_dofs, v_var*n_v_dofs, n_v_dofs, n_v_dofs); Kvw.reposition (v_var*n_v_dofs, w_var*n_v_dofs, n_v_dofs, n_w_dofs); #if INCOMPRESSIBLE Kvp.reposition (v_var*n_v_dofs, p_var*n_v_dofs, n_v_dofs, n_p_dofs); #endif Kwu.reposition (w_var*n_w_dofs, u_var*n_w_dofs, n_w_dofs, n_u_dofs); Kwv.reposition (w_var*n_w_dofs, v_var*n_w_dofs, n_w_dofs, n_v_dofs); Kww.reposition (w_var*n_w_dofs, w_var*n_w_dofs, n_w_dofs, n_w_dofs); #if INCOMPRESSIBLE Kwp.reposition (w_var*n_w_dofs, p_var*n_w_dofs, n_w_dofs, n_p_dofs); Kpu.reposition (p_var*n_u_dofs, u_var*n_u_dofs, n_p_dofs, n_u_dofs); Kpv.reposition (p_var*n_u_dofs, v_var*n_u_dofs, n_p_dofs, n_v_dofs); Kpw.reposition (p_var*n_u_dofs, w_var*n_u_dofs, n_p_dofs, n_w_dofs); Kpp.reposition (p_var*n_u_dofs, p_var*n_u_dofs, n_p_dofs, n_p_dofs); #endif Fu.reposition (u_var*n_u_dofs, n_u_dofs); Fv.reposition (v_var*n_u_dofs, n_v_dofs); Fw.reposition (w_var*n_u_dofs, n_w_dofs); #if INCOMPRESSIBLE Fp.reposition (p_var*n_u_dofs, n_p_dofs); #endif #if INERTIA //B block Kua.reposition (u_var*n_u_dofs, 3*n_u_dofs + n_p_dofs, n_u_dofs, n_u_dofs); Kub.reposition (u_var*n_u_dofs, 4*n_u_dofs + n_p_dofs, n_u_dofs, n_v_dofs); Kuc.reposition (u_var*n_u_dofs, 5*n_u_dofs + n_p_dofs, n_u_dofs, n_w_dofs); Kva.reposition (v_var*n_v_dofs, 3*n_u_dofs + n_p_dofs, n_v_dofs, n_u_dofs); Kvb.reposition (v_var*n_v_dofs, 4*n_u_dofs + n_p_dofs, n_v_dofs, n_v_dofs); Kvc.reposition (v_var*n_v_dofs, 5*n_u_dofs + n_p_dofs, n_v_dofs, n_w_dofs); Kwa.reposition (w_var*n_w_dofs, 3*n_u_dofs + n_p_dofs, n_w_dofs, n_u_dofs); Kwb.reposition (w_var*n_w_dofs, 4*n_u_dofs + n_p_dofs, n_w_dofs, n_v_dofs); Kwc.reposition (w_var*n_w_dofs, 5*n_u_dofs + n_p_dofs, n_w_dofs, n_w_dofs); test(701); //C block Kau.reposition (3*n_u_dofs + n_p_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs); Kav.reposition (3*n_u_dofs + n_p_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs); Kaw.reposition (3*n_u_dofs + n_p_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs); Kbu.reposition (4*n_u_dofs + n_p_dofs, u_var*n_v_dofs, n_v_dofs, n_u_dofs); Kbv.reposition (4*n_u_dofs + n_p_dofs, v_var*n_v_dofs, n_v_dofs, n_v_dofs); Kbw.reposition (4*n_u_dofs + n_p_dofs, w_var*n_v_dofs, n_v_dofs, n_w_dofs); Kcu.reposition (5*n_u_dofs + n_p_dofs, u_var*n_w_dofs, n_w_dofs, n_u_dofs); Kcv.reposition (5*n_u_dofs + n_p_dofs, v_var*n_w_dofs, n_w_dofs, n_v_dofs); Kcw.reposition (5*n_u_dofs + n_p_dofs, w_var*n_w_dofs, n_w_dofs, n_w_dofs); //D block Kaa.reposition (3*n_u_dofs + n_p_dofs, 3*n_u_dofs + n_p_dofs, n_u_dofs, n_u_dofs); Kab.reposition (3*n_u_dofs + n_p_dofs, 4*n_u_dofs + n_p_dofs, n_u_dofs, n_v_dofs); Kac.reposition (3*n_u_dofs + n_p_dofs, 5*n_u_dofs + n_p_dofs, n_u_dofs, n_w_dofs); Kba.reposition (4*n_u_dofs + n_p_dofs, 3*n_u_dofs + n_p_dofs, n_v_dofs, n_u_dofs); Kbb.reposition (4*n_u_dofs + n_p_dofs, 4*n_u_dofs + n_p_dofs, n_v_dofs, n_v_dofs); Kbc.reposition (4*n_u_dofs + n_p_dofs, 5*n_u_dofs + n_p_dofs, n_v_dofs, n_w_dofs); Kca.reposition (5*n_u_dofs + n_p_dofs, 3*n_u_dofs + n_p_dofs, n_w_dofs, n_u_dofs); Kcb.reposition (5*n_u_dofs + n_p_dofs, 4*n_u_dofs + n_p_dofs, n_w_dofs, n_v_dofs); Kcc.reposition (5*n_u_dofs + n_p_dofs, 5*n_u_dofs + n_p_dofs, n_w_dofs, n_w_dofs); Fa.reposition (3*n_u_dofs + n_p_dofs, n_u_dofs); Fb.reposition (4*n_u_dofs + n_p_dofs, n_v_dofs); Fc.reposition (5*n_u_dofs + n_p_dofs, n_w_dofs); dof_map.dof_indices (elem, dof_indices_a, a_var); dof_map.dof_indices (elem, dof_indices_b, b_var); dof_map.dof_indices (elem, dof_indices_c, c_var); test(71); #endif System& aux_system = es.get_system<System>("Reference-Configuration"); std::vector<unsigned int> undefo_index; std::vector<unsigned int> vel_index; for (unsigned int qp=0; qp<qrule.n_points(); qp++) { Point rX; for (unsigned int l=0; l<n_u_dofs; l++) { rX(0) += phi[l][qp]*ref_sys.current_local_solution->el(dof_indices_u[l]); rX(1) += phi[l][qp]*ref_sys.current_local_solution->el(dof_indices_v[l]); rX(2) += phi[l][qp]*ref_sys.current_local_solution->el(dof_indices_w[l]); } #if INERTIA || DT test(72); Real rho_s=15; Point current_x; for (unsigned int l=0; l<n_u_dofs; l++) { current_x(0) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_u[l]); current_x(1) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_v[l]); current_x(2) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_w[l]); } Point old_x; for (unsigned int l=0; l<n_u_dofs; l++) { old_x(0) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_u[l]); old_x(1) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_v[l]); old_x(2) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_w[l]); } #if INERTIA Point old_vel; for (unsigned int l=0; l<n_u_dofs; l++) { old_vel(0) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_a[l]); old_vel(1) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_b[l]); old_vel(2) += phi[l][qp]*last_non_linear_soln.old_local_solution->el(dof_indices_c[l]); } Point current_vel; for (unsigned int l=0; l<n_u_dofs; l++) { current_vel(0) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_a[l]); current_vel(1) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_b[l]); current_vel(2) += phi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_c[l]); } #endif #if UN_MINUS_ONE Point unm1_x; for (unsigned int l=0; l<n_u_dofs; l++) { unm1_x(0) += phi[l][qp]*unm1.old_local_solution->el(dof_indices_u[l]); unm1_x(1) += phi[l][qp]*unm1.old_local_solution->el(dof_indices_v[l]); unm1_x(2) += phi[l][qp]*unm1.old_local_solution->el(dof_indices_w[l]); } #endif Point value_acc; Point value_acc_alt; #if DT for (unsigned int d = 0; d < dim; ++d) { value_acc_alt(d) = (rho_s)*( ((current_x(d)-rX(d))-(old_x(d)-rX(d)))-((old_x(d)-rX(d))- (unm1_x(d)-rX(d))) ); value_acc(d) = (rho_s)*((current_x(d))-2*(old_x(d))+ (unm1_x(d))); value_acc(d) = (rho_s)*((current_x(d))-(old_x(d))); } #endif Point res_1; Point res_2; #if INERTIA for (unsigned int d = 0; d < dim; ++d) { res_1(d) = (rho_s)*((current_vel(d))-(old_vel(d))); res_2(d) = current_x(d)-dt*current_vel(d)-old_x(d); } /* std::cout<<" current_vel "<<current_vel<<std::endl; std::cout<<" res_1 "<<res_1<<std::endl; std::cout<<" res_2 "<<res_2<<std::endl; */ #endif test(73); #endif Number p_solid = 0.; #if MOVING_MESH grad_u_mat(0) = grad_u_mat(1) = grad_u_mat(2) = 0; for (unsigned int d = 0; d < dim; ++d) { std::vector<Number> u_undefo; //Fills the vector di with the global degree of freedom indices for the element. :dof_indicies aux_system.get_dof_map().dof_indices(elem, undefo_index,d); aux_system.current_local_solution->get(undefo_index, u_undefo); for (unsigned int l = 0; l != n_u_dofs; l++) grad_u_mat(d).add_scaled(dphi[l][qp], u_undefo[l]); } #endif //#include "fixed_mesh_in_solid_assemble_code.txt" #if INCOMPRESSIBLE for (unsigned int l=0; l<n_p_dofs; l++) { p_solid += psi[l][qp]*last_non_linear_soln.current_local_solution->el(dof_indices_p[l]); } #endif #if INCOMPRESSIBLE Real m=0; Real p_fluid=0; #if FLUID_VEL for (unsigned int l=0; l<n_p_dofs; l++) { p_fluid += psi[l][qp]*fluid_system_vel.current_local_solution->el(dof_indices_p[l]); } //As outlined in Chappel p=(p_curr-p_old)/2 Real p_fluid_old=0; for (unsigned int l=0; l<n_p_dofs; l++) { p_fluid_old += psi[l][qp]*fluid_system_vel.old_local_solution->el(dof_indices_p[l]); } p_fluid=0.5*p_fluid+0.5*p_fluid_old; Real m_old=0; #if FLUID_P_CONST for (unsigned int l=0; l<n_p_dofs; l++) { m += psi[l][qp]*fluid_system_vel.current_local_solution->el(dof_indices_m[l]); } for (unsigned int l=0; l<n_p_dofs; l++) { m_old += psi[l][qp]*fluid_system_vel.old_local_solution->el(dof_indices_m[l]); } #endif material.init_for_qp(grad_u_mat, p_solid, qp, 1.0*m+0.0*m_old, p_fluid); #endif #endif //#if INCOMPRESSIBLE #if INCOMPRESSIBLE && ! PORO material.init_for_qp(grad_u_mat, p_solid, qp); #endif for (unsigned int i=0; i<n_u_dofs; i++) { res.resize(dim); material.get_residual(res, i); res.scale(JxW[qp]); #if INERTIA res.scale(dt); #endif #if DT res.scale(dt); #endif //std::cout<< "res "<<res<<std::endl; Fu(i) += res(0); Fv(i) += res(1) ; Fw(i) += res(2); #if GRAVITY Real grav=0.0; Fu(i) += progress*grav*JxW[qp]*phi[i][qp]; #endif #if INERTIA Fu(i) += JxW[qp]*phi[i][qp]*res_1(0); Fv(i) += JxW[qp]*phi[i][qp]*res_1(1); Fw(i) += JxW[qp]*phi[i][qp]*res_1(2); Fa(i) += JxW[qp]*phi[i][qp]*res_2(0); Fb(i) += JxW[qp]*phi[i][qp]*res_2(1); Fc(i) += JxW[qp]*phi[i][qp]*res_2(2); #endif // Matrix contributions for the uu and vv couplings. for (unsigned int j=0; j<n_u_dofs; j++) { material.get_linearized_stiffness(stiff, i, j); stiff.scale(JxW[qp]); #if DT res.scale(dt); #endif #if INERTIA stiff.scale(dt); Kua(i,j)+= rho_s*JxW[qp]*phi[i][qp]*phi[j][qp]; Kvb(i,j)+= rho_s*JxW[qp]*phi[i][qp]*phi[j][qp]; Kwc(i,j)+= rho_s*JxW[qp]*phi[i][qp]*phi[j][qp]; Kau(i,j)+= JxW[qp]*phi[i][qp]*phi[j][qp]; Kbv(i,j)+= JxW[qp]*phi[i][qp]*phi[j][qp]; Kcw(i,j)+= JxW[qp]*phi[i][qp]*phi[j][qp]; Kaa(i,j)+= -dt*JxW[qp]*phi[i][qp]*phi[j][qp]; Kbb(i,j)+= -dt*JxW[qp]*phi[i][qp]*phi[j][qp]; Kcc(i,j)+= -dt*JxW[qp]*phi[i][qp]*phi[j][qp]; #endif Kuu(i,j)+= stiff(u_var, u_var); Kuv(i,j)+= stiff(u_var, v_var); Kuw(i,j)+= stiff(u_var, w_var); Kvu(i,j)+= stiff(v_var, u_var); Kvv(i,j)+= stiff(v_var, v_var); Kvw(i,j)+= stiff(v_var, w_var); Kwu(i,j)+= stiff(w_var, u_var); Kwv(i,j)+= stiff(w_var, v_var); Kww(i,j)+= stiff(w_var, w_var); #if GRAVITY Kuu(i,j)+= 1*JxW[qp]*phi[i][qp]*phi[j][qp]; #endif } } #if INCOMPRESSIBLE && FLUID_P_CONST for (unsigned int i = 0; i < n_p_dofs; i++) { material.get_p_residual(p_res, i); p_res.scale(JxW[qp]); Fp(i) += p_res(0); } for (unsigned int i = 0; i < n_u_dofs; i++) { for (unsigned int j = 0; j < n_p_dofs; j++) { material.get_linearized_uvw_p_stiffness(p_stiff, i, j); p_stiff.scale(JxW[qp]); Kup(i, j) += p_stiff(0); Kvp(i, j) += p_stiff(1); Kwp(i, j) += p_stiff(2); } } for (unsigned int i = 0; i < n_p_dofs; i++) { for (unsigned int j = 0; j < n_u_dofs; j++) { material.get_linearized_p_uvw_stiffness(p_stiff, i, j); p_stiff.scale(JxW[qp]); Kpu(i, j) += p_stiff(0); Kpv(i, j) += p_stiff(1); Kpw(i, j) += p_stiff(2); } } #endif #if CHAP && ! FLUID_P_CONST for (unsigned int i = 0; i < n_p_dofs; i++) { Fp(i) += 0*JxW[qp]*psi[i][qp]; } for (unsigned int i = 0; i < n_p_dofs; i++) { for (unsigned int j = 0; j < n_p_dofs; j++) { Kpp(i, j) += 1*JxW[qp]*psi[i][qp]*psi[j][qp]; } } #endif }//end of qp loop newton_update.matrix->add_matrix (Ke, dof_indices); newton_update.rhs->add_vector (Fe, dof_indices); } // end of element loop // dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices); newton_update.rhs->close(); newton_update.matrix->close(); #if LOG_ASSEMBLE_PERFORMANCE perf_log.pop("assemble stiffness"); #endif #if LOG_ASSEMBLE_PERFORMANCE perf_log.push("assemble bcs"); #endif //Assemble the boundary conditions. assemble_bcs(es); #if LOG_ASSEMBLE_PERFORMANCE perf_log.pop("assemble bcs"); #endif std::ofstream lhs_out("lhsoutS3.dat"); Ke.print(lhs_out); lhs_out.close(); return; }