Nektar++
Loading...
Searching...
No Matches
Classes | Functions | Variables
check_imexdirk_forced_mms_2d Namespace Reference

Classes

class  Poly
 

Functions

 as_poly (value)
 
 adv (component)
 
 install_manufactured_solution (text)
 
 check_mixed_tri_quad_mesh (text, session)
 
 set_time_integration (text, method, order)
 
 replace_parameter (text, name, value)
 
 build_session (args, workdir, order, formulation)
 
 run_case (args, workdir, order, formulation)
 
 parse_int_map (values)
 
 parse_str_map (values)
 
 main ()
 

Variables

list VELOCITY_VARS = ["u", "v"]
 
dict DEFAULT_METHOD_BY_ORDER = {2: "IMEXdirk23", 3: "IMEXdirk23"}
 
dict DEFAULT_STEPS_BY_ORDER = {2: 4, 3: 4}
 
 x = Poly.var(0)
 
 y = Poly.var(1)
 
 X = x * (3.0 - x)
 
 Y = y * (3.0 - y)
 
tuple psi = (X**2) * (Y**2)
 
tuple u0 = psi.deriv(1)
 
tuple v0 = -psi.deriv(0)
 
tuple p0 = (x - 1.5) * (y - 1.5)
 
str A = "(1+0.1*sin(t))"
 
str AT = "(0.1*cos(t))"
 
str A0 = "1"
 
tuple U0 = u0.expr()
 
tuple V0 = v0.expr()
 
tuple P0 = p0.expr()
 
str U = f"{A}*{U0}"
 
str V = f"{A}*{V0}"
 
tuple P = P0
 
 ADV_U = adv(u0).expr()
 
 ADV_V = adv(v0).expr()
 
tuple PX = p0.deriv(0).expr()
 
tuple PY = p0.deriv(1).expr()
 
tuple LAP_U = u0.lap().expr()
 
tuple LAP_V = v0.lap().expr()
 
str FORCE_U = f"{AT}*{U0}+{A}*{A}*{ADV_U}+{PX}-Kinvis*{A}*{LAP_U}"
 
str FORCE_V = f"{AT}*{V0}+{A}*{A}*{ADV_V}+{PY}-Kinvis*{A}*{LAP_V}"
 
str MANUFACTURED_FUNCTIONS
 
str FORCING_BLOCK
 
str BOUNDARY_CONDITIONS
 

Function Documentation

◆ adv()

check_imexdirk_forced_mms_2d.adv (   component)

Definition at line 121 of file check_imexdirk_forced_mms_2d.py.

121def adv(component):
122 return u0 * component.deriv(0) + v0 * component.deriv(1)
123
124

◆ as_poly()

check_imexdirk_forced_mms_2d.as_poly (   value)

Definition at line 104 of file check_imexdirk_forced_mms_2d.py.

104def as_poly(value):
105 return value if isinstance(value, Poly) else Poly.const(value)
106
107

Referenced by check_imexdirk_forced_mms_2d.Poly.__add__(), check_imexdirk_forced_mms_2d.Poly.__mul__(), check_imexdirk_forced_mms_2d.Poly.__rsub__(), and check_imexdirk_forced_mms_2d.Poly.__sub__().

◆ build_session()

check_imexdirk_forced_mms_2d.build_session (   args,
  workdir,
  order,
  formulation 
)

Definition at line 239 of file check_imexdirk_forced_mms_2d.py.

239def build_session(args, workdir, order, formulation):
240 text = args.session.read_text()
241 check_mixed_tri_quad_mesh(text, args.session)
242 method = args.method_by_order.get(order, DEFAULT_METHOD_BY_ORDER[order])
243 nsteps = args.steps_by_order.get(order, DEFAULT_STEPS_BY_ORDER[order])
244 dt = args.final_time / nsteps
245
246 text = set_time_integration(text, method, order)
247 text = replace_parameter(text, "TimeStep", f"{dt:.16g}")
248 text = replace_parameter(text, "NumSteps", str(nsteps))
249 text = replace_parameter(text, "IO_InfoSteps", str(nsteps))
250 text = replace_parameter(text, "Kinvis", f"{args.kinvis:.16g}")
251 text = replace_parameter(text, "IterativeSolverTolerance", "1e-10")
252 text = re.sub(r'NUMMODES="\d+"', f'NUMMODES="{args.num_modes}"', text)
253 text = install_manufactured_solution(text)
254
255 # formulation is baked into the filename (not the file content - it's
256 # applied via -I on the command line) purely so concurrent cases that
257 # share an order never write/read the same path.
258 session = workdir / f"forced_mms_2d_{method}_order{order}_{formulation}.xml"
259 session.write_text(text)
260 return session
261
262

References check_mixed_tri_quad_mesh(), install_manufactured_solution(), replace_parameter(), and set_time_integration().

Referenced by run_case().

◆ check_mixed_tri_quad_mesh()

check_imexdirk_forced_mms_2d.check_mixed_tri_quad_mesh (   text,
  session 
)

Definition at line 208 of file check_imexdirk_forced_mms_2d.py.

208def check_mixed_tri_quad_mesh(text, session):
209 ntri = len(re.findall(r"<T\s+ID=", text))
210 nquad = len(re.findall(r"<Q\s+ID=", text))
211 if ntri == 0 or nquad == 0:
212 raise RuntimeError(
213 f"{session} must contain both triangles and quads; "
214 f"found {ntri} triangles and {nquad} quads"
215 )
216
217

Referenced by build_session().

◆ install_manufactured_solution()

check_imexdirk_forced_mms_2d.install_manufactured_solution (   text)

Definition at line 183 of file check_imexdirk_forced_mms_2d.py.

183def install_manufactured_solution(text):
184 text = re.sub(
185 r" <BOUNDARYREGIONS>.*?</BOUNDARYCONDITIONS>",
186 BOUNDARY_CONDITIONS,
187 text,
188 flags=re.DOTALL,
189 )
190 text = re.sub(
191 r"\n\s*<FUNCTION NAME=\"InitialConditions\">.*?</FUNCTION>\s*"
192 r"<FUNCTION NAME=\"ExactSolution\">.*?</FUNCTION>",
193 "\n" + MANUFACTURED_FUNCTIONS,
194 text,
195 flags=re.DOTALL,
196 )
197 text = re.sub(
198 r"\n\s*<(?:FORCING|Forcing)>.*?</(?:FORCING|Forcing)>",
199 "",
200 text,
201 flags=re.DOTALL,
202 )
203 text = re.sub(r"\n\s*<FILTERS>.*?</FILTERS>", "", text, flags=re.DOTALL)
204 text = re.sub(r"\n\s*</NEKTAR>", f"\n{FORCING_BLOCK}\n</NEKTAR>", text)
205 return text
206
207

Referenced by build_session().

◆ main()

check_imexdirk_forced_mms_2d.main ( )

Definition at line 312 of file check_imexdirk_forced_mms_2d.py.

312def main():
313 parser = argparse.ArgumentParser()
314 parser.add_argument("--solver", type=pathlib.Path, required=True)
315 parser.add_argument("--session", type=pathlib.Path, required=True)
316 parser.add_argument("--op-exec-space", default="Serial")
317 parser.add_argument("--op-impl", default="SumFac")
318 parser.add_argument("--orders", nargs="+", type=int, default=[2, 3])
319 parser.add_argument("--formulations", nargs="+", default=["linearimplicit"])
320 parser.add_argument("--steps", action="append", default=[], metavar="ORDER=N")
321 parser.add_argument("--method", action="append", default=[], metavar="ORDER=METHOD")
322 parser.add_argument("--final-time", type=float, default=0.02)
323 parser.add_argument("--kinvis", type=float, default=0.05)
324 parser.add_argument("--num-modes", type=int, default=7)
325 parser.add_argument("--timeout", type=float, default=600.0)
326 parser.add_argument(
327 "--max-workers",
328 type=int,
329 default=4,
330 help=(
331 "Cap on concurrent solver subprocesses. This test runs as a "
332 "single slot under ctest's own -j parallelism, so this must "
333 "stay well below the host core count to avoid oversubscribing "
334 "it (see the matching PROCESSORS test property in "
335 "CMakeLists.txt, and check_time_order.py which uses the same "
336 "pattern)."
337 ),
338 )
339 args = parser.parse_args()
340
341 args.solver = args.solver.resolve()
342 args.session = args.session.resolve()
343 args.steps_by_order = parse_int_map(args.steps)
344 args.method_by_order = parse_str_map(args.method)
345
346 failed = False
347 with tempfile.TemporaryDirectory(prefix="incns_imexdirk_mms2d_") as tmp:
348 workdir = pathlib.Path(tmp)
349
350 # Each (order, formulation) case below is its own single-threaded
351 # Nektar++ subprocess with its own uniquely-named session file (see
352 # build_session) - Nektar++ itself is never asked to use more than
353 # one thread; only the orchestration here is concurrent.
354 cases = [
355 (order, formulation)
356 for order in args.orders
357 for formulation in args.formulations
358 ]
359 max_workers = min(len(cases), max(1, args.max_workers))
360 with ThreadPoolExecutor(max_workers=max_workers) as pool:
361 results = list(
362 pool.map(lambda c: run_case(args, workdir, c[0], c[1]), cases)
363 )
364
365 for (order, formulation), (ok, proc) in zip(cases, results):
366 label = f"order={order} formulation={formulation}"
367 if ok:
368 print(f"{label}: passed", flush=True)
369 else:
370 print(f"{label}: failed", flush=True)
371 print("=== stdout ===", flush=True)
372 print(proc.stdout, flush=True)
373 print("=== stderr ===", flush=True)
374 print(proc.stderr, flush=True)
375 failed = True
376
377 if failed:
378 raise SystemExit(1)
379
380
Definition main.py:1

References parse_int_map(), parse_str_map(), and run_case().

◆ parse_int_map()

check_imexdirk_forced_mms_2d.parse_int_map (   values)

Definition at line 296 of file check_imexdirk_forced_mms_2d.py.

296def parse_int_map(values):
297 out = {}
298 for value in values:
299 key, val = value.split("=", 1)
300 out[int(key)] = int(val)
301 return out
302
303

Referenced by main().

◆ parse_str_map()

check_imexdirk_forced_mms_2d.parse_str_map (   values)

Definition at line 304 of file check_imexdirk_forced_mms_2d.py.

304def parse_str_map(values):
305 out = {}
306 for value in values:
307 key, val = value.split("=", 1)
308 out[int(key)] = val
309 return out
310
311

Referenced by main().

◆ replace_parameter()

check_imexdirk_forced_mms_2d.replace_parameter (   text,
  name,
  value 
)

Definition at line 231 of file check_imexdirk_forced_mms_2d.py.

231def replace_parameter(text, name, value):
232 return re.sub(
233 rf"<P>\s*{name}\s*=\s*[^<]+</P>",
234 f"<P> {name} = {value} </P>",
235 text,
236 )
237
238

Referenced by build_session().

◆ run_case()

check_imexdirk_forced_mms_2d.run_case (   args,
  workdir,
  order,
  formulation 
)

Definition at line 263 of file check_imexdirk_forced_mms_2d.py.

263def run_case(args, workdir, order, formulation):
264 session = build_session(args, workdir, order, formulation)
265 cmd = [
266 str(args.solver),
267 f"--opExecSpace={args.op_exec_space}",
268 f"--opImpl={args.op_impl}",
269 "-I",
270 f"Formulation={formulation}",
271 str(session),
272 ]
273 proc = subprocess.run(
274 cmd,
275 cwd=workdir,
276 text=True,
277 stdout=subprocess.PIPE,
278 stderr=subprocess.PIPE,
279 timeout=args.timeout,
280 )
281
282 if proc.returncode:
283 return False, proc
284
285 missing = []
286 for var in VELOCITY_VARS:
287 if not re.search(rf"L 2 error \‍(variable {var}\‍) : ([0-9.eE+-]+)", proc.stdout):
288 missing.append(var)
289 if missing:
290 proc.stderr += "\nMissing L2 output for: " + ", ".join(missing)
291 return False, proc
292
293 return True, proc
294
295

References build_session().

Referenced by main().

◆ set_time_integration()

check_imexdirk_forced_mms_2d.set_time_integration (   text,
  method,
  order 
)

Definition at line 218 of file check_imexdirk_forced_mms_2d.py.

218def set_time_integration(text, method, order):
219 replacement = f""" <TIMEINTEGRATIONSCHEME>
220 <METHOD> {method} </METHOD>
221 <ORDER> {order} </ORDER>
222 </TIMEINTEGRATIONSCHEME>"""
223 return re.sub(
224 r" <TIMEINTEGRATIONSCHEME>.*?</TIMEINTEGRATIONSCHEME>",
225 replacement,
226 text,
227 flags=re.DOTALL,
228 )
229
230

Referenced by build_session().

Variable Documentation

◆ A

str check_imexdirk_forced_mms_2d.A = "(1+0.1*sin(t))"

Definition at line 125 of file check_imexdirk_forced_mms_2d.py.

◆ A0

str check_imexdirk_forced_mms_2d.A0 = "1"

Definition at line 127 of file check_imexdirk_forced_mms_2d.py.

◆ ADV_U

check_imexdirk_forced_mms_2d.ADV_U = adv(u0).expr()

Definition at line 136 of file check_imexdirk_forced_mms_2d.py.

◆ ADV_V

check_imexdirk_forced_mms_2d.ADV_V = adv(v0).expr()

Definition at line 137 of file check_imexdirk_forced_mms_2d.py.

◆ AT

str check_imexdirk_forced_mms_2d.AT = "(0.1*cos(t))"

Definition at line 126 of file check_imexdirk_forced_mms_2d.py.

◆ BOUNDARY_CONDITIONS

str check_imexdirk_forced_mms_2d.BOUNDARY_CONDITIONS
Initial value:
1= f""" <BOUNDARYREGIONS>
2 <B ID="0"> C[2-5] </B>
3 </BOUNDARYREGIONS>
4
5 <BOUNDARYCONDITIONS>
6 <REGION REF="0">
7 <D VAR="u" VALUE="{U}" />
8 <D VAR="v" VALUE="{V}" />
9 <D VAR="p" VALUE="{P}" />
10 </REGION>
11 </BOUNDARYCONDITIONS>"""

Definition at line 170 of file check_imexdirk_forced_mms_2d.py.

◆ DEFAULT_METHOD_BY_ORDER

dict check_imexdirk_forced_mms_2d.DEFAULT_METHOD_BY_ORDER = {2: "IMEXdirk23", 3: "IMEXdirk23"}

Definition at line 11 of file check_imexdirk_forced_mms_2d.py.

◆ DEFAULT_STEPS_BY_ORDER

dict check_imexdirk_forced_mms_2d.DEFAULT_STEPS_BY_ORDER = {2: 4, 3: 4}

Definition at line 12 of file check_imexdirk_forced_mms_2d.py.

◆ FORCE_U

str check_imexdirk_forced_mms_2d.FORCE_U = f"{AT}*{U0}+{A}*{A}*{ADV_U}+{PX}-Kinvis*{A}*{LAP_U}"

Definition at line 143 of file check_imexdirk_forced_mms_2d.py.

◆ FORCE_V

str check_imexdirk_forced_mms_2d.FORCE_V = f"{AT}*{V0}+{A}*{A}*{ADV_V}+{PY}-Kinvis*{A}*{LAP_V}"

Definition at line 144 of file check_imexdirk_forced_mms_2d.py.

◆ FORCING_BLOCK

str check_imexdirk_forced_mms_2d.FORCING_BLOCK
Initial value:
1= """ <FORCING>
2 <FORCE TYPE="Body">
3 <BODYFORCE> BodyForce </BODYFORCE>
4 </FORCE>
5 </FORCING>"""

Definition at line 164 of file check_imexdirk_forced_mms_2d.py.

◆ LAP_U

tuple check_imexdirk_forced_mms_2d.LAP_U = u0.lap().expr()

Definition at line 140 of file check_imexdirk_forced_mms_2d.py.

◆ LAP_V

tuple check_imexdirk_forced_mms_2d.LAP_V = v0.lap().expr()

Definition at line 141 of file check_imexdirk_forced_mms_2d.py.

◆ MANUFACTURED_FUNCTIONS

str check_imexdirk_forced_mms_2d.MANUFACTURED_FUNCTIONS
Initial value:
1= f""" <FUNCTION NAME="InitialConditions">
2 <E VAR="u" VALUE="{A0}*{U0}" />
3 <E VAR="v" VALUE="{A0}*{V0}" />
4 <E VAR="p" VALUE="{P0}" />
5 </FUNCTION>
6
7 <FUNCTION NAME="ExactSolution">
8 <E VAR="u" VALUE="{U}" />
9 <E VAR="v" VALUE="{V}" />
10 <E VAR="p" VALUE="{P}" />
11 </FUNCTION>
12
13 <FUNCTION NAME="BodyForce">
14 <E VAR="u" VALUE="{FORCE_U}" />
15 <E VAR="v" VALUE="{FORCE_V}" />
16 <E VAR="p" VALUE="0" />
17 </FUNCTION>"""

Definition at line 146 of file check_imexdirk_forced_mms_2d.py.

◆ P

tuple check_imexdirk_forced_mms_2d.P = P0

Definition at line 134 of file check_imexdirk_forced_mms_2d.py.

◆ p0

tuple check_imexdirk_forced_mms_2d.p0 = (x - 1.5) * (y - 1.5)

Definition at line 118 of file check_imexdirk_forced_mms_2d.py.

◆ P0

tuple check_imexdirk_forced_mms_2d.P0 = p0.expr()

Definition at line 131 of file check_imexdirk_forced_mms_2d.py.

◆ psi

tuple check_imexdirk_forced_mms_2d.psi = (X**2) * (Y**2)

Definition at line 115 of file check_imexdirk_forced_mms_2d.py.

◆ PX

tuple check_imexdirk_forced_mms_2d.PX = p0.deriv(0).expr()

Definition at line 138 of file check_imexdirk_forced_mms_2d.py.

◆ PY

tuple check_imexdirk_forced_mms_2d.PY = p0.deriv(1).expr()

Definition at line 139 of file check_imexdirk_forced_mms_2d.py.

◆ U

str check_imexdirk_forced_mms_2d.U = f"{A}*{U0}"

Definition at line 132 of file check_imexdirk_forced_mms_2d.py.

◆ u0

tuple check_imexdirk_forced_mms_2d.u0 = psi.deriv(1)

Definition at line 116 of file check_imexdirk_forced_mms_2d.py.

◆ U0

tuple check_imexdirk_forced_mms_2d.U0 = u0.expr()

Definition at line 129 of file check_imexdirk_forced_mms_2d.py.

◆ V

str check_imexdirk_forced_mms_2d.V = f"{A}*{V0}"

Definition at line 133 of file check_imexdirk_forced_mms_2d.py.

◆ v0

tuple check_imexdirk_forced_mms_2d.v0 = -psi.deriv(0)

Definition at line 117 of file check_imexdirk_forced_mms_2d.py.

◆ V0

tuple check_imexdirk_forced_mms_2d.V0 = v0.expr()

Definition at line 130 of file check_imexdirk_forced_mms_2d.py.

◆ VELOCITY_VARS

list check_imexdirk_forced_mms_2d.VELOCITY_VARS = ["u", "v"]

Definition at line 10 of file check_imexdirk_forced_mms_2d.py.

◆ x

check_imexdirk_forced_mms_2d.x = Poly.var(0)

Definition at line 108 of file check_imexdirk_forced_mms_2d.py.

◆ X

check_imexdirk_forced_mms_2d.X = x * (3.0 - x)

Definition at line 113 of file check_imexdirk_forced_mms_2d.py.

◆ y

check_imexdirk_forced_mms_2d.y = Poly.var(1)

Definition at line 109 of file check_imexdirk_forced_mms_2d.py.

◆ Y

check_imexdirk_forced_mms_2d.Y = y * (3.0 - y)

Definition at line 114 of file check_imexdirk_forced_mms_2d.py.