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

Classes

class  Poly
 

Functions

 as_poly (value)
 
 adv (component)
 
 install_manufactured_solution (text)
 
 build_session (base_session, workdir, formulation, order, nsteps, final_time)
 
 run_case (args, workdir, formulation, order, nsteps)
 
 observed_rates (errors)
 
 main ()
 

Variables

dict MIN_RATES = {1: 0.85, 2: 1.70, 3: 2.30}
 
dict NSTEPS_BY_ORDER = {1: [2, 4], 2: [2, 4], 3: [2, 4]}
 
list FORMULATIONS = ["semiimplicit", "linearimplicit"]
 
list VELOCITY_VARS = ["u", "v", "w"]
 
 x = Poly.var(0)
 
 y = Poly.var(1)
 
 z = Poly.var(2)
 
tuple X = (x + 0.5) * (1.0 - x)
 
tuple Y = (y + 0.5) * (1.5 - y)
 
 Z = z * (1.0 - z)
 
tuple phi = (X**2) * (Y**2) * (Z**2)
 
tuple phi_x = phi.deriv(0)
 
tuple phi_y = phi.deriv(1)
 
tuple phi_z = phi.deriv(2)
 
list q = [phi_y - phi_z, phi_z - phi_x, phi_x - phi_y]
 
 p0 = x * y + y * z + z * x
 
str A = "(1+0.1*sin(t))"
 
str AT = "(0.1*cos(t))"
 
str A0 = "1"
 
 U0
 
 V0
 
 W0
 
 P0 = p0.expr()
 
str U = f"{A}*{U0}"
 
str V = f"{A}*{V0}"
 
str W = f"{A}*{W0}"
 
 P = P0
 
 ADV_U
 
 ADV_V
 
 ADV_W
 
 PX
 
 PY
 
 PZ
 
 LAP_U
 
 LAP_V
 
 LAP_W
 
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 FORCE_W = f"{AT}*{W0}+{A}*{A}*{ADV_W}+{PZ}-Kinvis*{A}*{LAP_W}"
 
str MANUFACTURED_FUNCTIONS
 
str FORCING_BLOCK
 
str BOUNDARY_CONDITIONS
 

Function Documentation

◆ adv()

check_time_order.adv (   component)

Definition at line 123 of file check_time_order.py.

123def adv(component):
124 return q[0] * component.deriv(0) + q[1] * component.deriv(1) + q[2] * component.deriv(2)
125

◆ as_poly()

check_time_order.as_poly (   value)

Definition at line 104 of file check_time_order.py.

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

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

◆ build_session()

check_time_order.build_session (   base_session,
  workdir,
  formulation,
  order,
  nsteps,
  final_time 
)

Definition at line 206 of file check_time_order.py.

206def build_session(base_session, workdir, formulation, order, nsteps, final_time):
207 text = base_session.read_text()
208 dt = final_time / nsteps
209
210 text = re.sub(r"<ORDER>\s*\d+\s*</ORDER>", f"<ORDER> {order} </ORDER>", text)
211 text = re.sub(
212 r"<P>\s*TimeStep\s*=\s*[^<]+</P>",
213 f"<P> TimeStep = {dt:.16g} </P>",
214 text,
215 )
216 text = re.sub(
217 r"<P>\s*NumSteps\s*=\s*[^<]+</P>",
218 f"<P> NumSteps = {nsteps} </P>",
219 text,
220 )
221 text = re.sub(
222 r"<P>\s*IO_InfoSteps\s*=\s*[^<]+</P>",
223 f"<P> IO_InfoSteps = {nsteps} </P>",
224 text,
225 )
226 text = re.sub(r'NUMMODES="\d+"', 'NUMMODES="5"', text)
227 text = re.sub(
228 r"<P>\s*IterativeSolverTolerance\s*=\s*[^<]+</P>",
229 "<P> IterativeSolverTolerance = 1e-7 </P>",
230 text,
231 )
232 text = re.sub(
233 r"<P>\s*NekLinSysMaxIterations\s*=\s*[^<]+</P>",
234 "<P> NekLinSysMaxIterations = 1000 </P>",
235 text,
236 )
237 text = install_manufactured_solution(text)
238
239 session = workdir / f"manufactured3d_order{order}_{formulation}_{nsteps}.xml"
240 session.write_text(text)
241 return session
242
243

References install_manufactured_solution().

Referenced by run_case().

◆ install_manufactured_solution()

check_time_order.install_manufactured_solution (   text)

Definition at line 186 of file check_time_order.py.

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

Referenced by build_session().

◆ main()

check_time_order.main ( )

Definition at line 287 of file check_time_order.py.

287def main():
288 parser = argparse.ArgumentParser()
289 parser.add_argument("--solver", type=pathlib.Path, required=True)
290 parser.add_argument("--session", type=pathlib.Path, required=True)
291 parser.add_argument("--op-exec-space", default="Serial")
292 parser.add_argument("--op-impl", default="SumFac")
293 parser.add_argument("--final-time", type=float, default=0.2)
294 parser.add_argument("--timeout", type=float, default=600.0)
295 parser.add_argument(
296 "--max-workers",
297 type=int,
298 default=4,
299 help=(
300 "Cap on concurrent solver subprocesses. This test runs as a "
301 "single slot under ctest's own -j parallelism, so this must "
302 "stay well below os.cpu_count() to avoid oversubscribing the "
303 "host (see IncNavierStokesSolverRedesign_TimeIntegrationOrders123_* "
304 "PROCESSORS test property, which should match this default)."
305 ),
306 )
307 args = parser.parse_args()
308 args.solver = args.solver.resolve()
309 args.session = args.session.resolve()
310
311 with tempfile.TemporaryDirectory(prefix="incns_time_order_") as tmp:
312 workdir = pathlib.Path(tmp)
313 failed = False
314
315 # Each (order, formulation, nsteps) case below is its own
316 # single-threaded Nektar++ subprocess with no shared state (unique
317 # session file, no output files written) - Nektar++ itself is never
318 # asked to use more than one thread; only the orchestration here is
319 # concurrent.
320 cases = [
321 (order, formulation, nsteps)
322 for order in [1, 2, 3]
323 for formulation in FORMULATIONS
324 for nsteps in NSTEPS_BY_ORDER[order]
325 ]
326 max_workers = min(len(cases), max(1, args.max_workers))
327 with ThreadPoolExecutor(max_workers=max_workers) as pool:
328 case_errors = dict(
329 zip(
330 cases,
331 pool.map(
332 lambda c: run_case(args, workdir, c[1], c[0], c[2]), cases
333 ),
334 )
335 )
336
337 for order in [1, 2, 3]:
338 for formulation in FORMULATIONS:
339 errors = [
340 case_errors[(order, formulation, nsteps)]
341 for nsteps in NSTEPS_BY_ORDER[order]
342 ]
343 rates = observed_rates(errors)
344 min_rate = MIN_RATES[order]
345
346 print(
347 f"order={order} {formulation}: "
348 f"errors={errors} rates={rates}",
349 flush=True,
350 )
351
352 if rates[-1] < min_rate:
353 print(
354 f"order={order} {formulation}: expected final "
355 f"observed order >= {min_rate}, got {rates[-1]}",
356 flush=True,
357 )
358 failed = True
359
360 if failed:
361 raise SystemExit(1)
362
363
Definition main.py:1

References observed_rates(), and run_case().

◆ observed_rates()

check_time_order.observed_rates (   errors)

Definition at line 283 of file check_time_order.py.

283def observed_rates(errors):
284 return [math.log(errors[i - 1] / errors[i], 2.0) for i in range(1, len(errors))]
285
286

Referenced by main().

◆ run_case()

check_time_order.run_case (   args,
  workdir,
  formulation,
  order,
  nsteps 
)

Definition at line 244 of file check_time_order.py.

244def run_case(args, workdir, formulation, order, nsteps):
245 session = build_session(
246 args.session, workdir, formulation, order, nsteps, args.final_time
247 )
248 cmd = [
249 str(args.solver),
250 f"--opExecSpace={args.op_exec_space}",
251 f"--opImpl={args.op_impl}",
252 "-I",
253 f"Formulation={formulation}",
254 str(session),
255 ]
256 proc = subprocess.run(
257 cmd,
258 cwd=workdir,
259 text=True,
260 stdout=subprocess.PIPE,
261 stderr=subprocess.PIPE,
262 timeout=args.timeout,
263 )
264 if proc.returncode:
265 print(proc.stdout)
266 print(proc.stderr)
267 raise RuntimeError(
268 f"order={order} {formulation} nsteps={nsteps} failed"
269 )
270
271 errors = []
272 for var in VELOCITY_VARS:
273 match = re.search(rf"L 2 error \‍(variable {var}\‍) : ([0-9.eE+-]+)", proc.stdout)
274 if not match:
275 print(proc.stdout)
276 raise RuntimeError(
277 f"order={order} {formulation} nsteps={nsteps} did not report {var} L2"
278 )
279 errors.append(float(match.group(1)))
280 return max(errors)
281
282

References build_session().

Referenced by main().

Variable Documentation

◆ A

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

Definition at line 126 of file check_time_order.py.

◆ A0

str check_time_order.A0 = "1"

Definition at line 128 of file check_time_order.py.

◆ ADV_U

check_time_order.ADV_U

Definition at line 137 of file check_time_order.py.

◆ ADV_V

check_time_order.ADV_V

Definition at line 137 of file check_time_order.py.

◆ ADV_W

check_time_order.ADV_W

Definition at line 137 of file check_time_order.py.

◆ AT

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

Definition at line 127 of file check_time_order.py.

◆ BOUNDARY_CONDITIONS

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

Definition at line 172 of file check_time_order.py.

◆ FORCE_U

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

Definition at line 141 of file check_time_order.py.

◆ FORCE_V

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

Definition at line 142 of file check_time_order.py.

◆ FORCE_W

str check_time_order.FORCE_W = f"{AT}*{W0}+{A}*{A}*{ADV_W}+{PZ}-Kinvis*{A}*{LAP_W}"

Definition at line 143 of file check_time_order.py.

◆ FORCING_BLOCK

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

Definition at line 166 of file check_time_order.py.

◆ FORMULATIONS

list check_time_order.FORMULATIONS = ["semiimplicit", "linearimplicit"]

Definition at line 14 of file check_time_order.py.

◆ LAP_U

check_time_order.LAP_U

Definition at line 139 of file check_time_order.py.

◆ LAP_V

check_time_order.LAP_V

Definition at line 139 of file check_time_order.py.

◆ LAP_W

check_time_order.LAP_W

Definition at line 139 of file check_time_order.py.

◆ MANUFACTURED_FUNCTIONS

str check_time_order.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="w" VALUE="{A0}*{W0}" />
5 <E VAR="p" VALUE="{P0}" />
6 </FUNCTION>
7
8 <FUNCTION NAME="ExactSolution">
9 <E VAR="u" VALUE="{U}" />
10 <E VAR="v" VALUE="{V}" />
11 <E VAR="w" VALUE="{W}" />
12 <E VAR="p" VALUE="{P}" />
13 </FUNCTION>
14
15 <FUNCTION NAME="BodyForce">
16 <E VAR="u" VALUE="{FORCE_U}" />
17 <E VAR="v" VALUE="{FORCE_V}" />
18 <E VAR="w" VALUE="{FORCE_W}" />
19 <E VAR="p" VALUE="0" />
20 </FUNCTION>"""

Definition at line 145 of file check_time_order.py.

◆ MIN_RATES

dict check_time_order.MIN_RATES = {1: 0.85, 2: 1.70, 3: 2.30}

Definition at line 12 of file check_time_order.py.

◆ NSTEPS_BY_ORDER

dict check_time_order.NSTEPS_BY_ORDER = {1: [2, 4], 2: [2, 4], 3: [2, 4]}

Definition at line 13 of file check_time_order.py.

◆ P

check_time_order.P = P0

Definition at line 135 of file check_time_order.py.

◆ p0

check_time_order.p0 = x * y + y * z + z * x

Definition at line 121 of file check_time_order.py.

◆ P0

check_time_order.P0 = p0.expr()

Definition at line 131 of file check_time_order.py.

◆ phi

tuple check_time_order.phi = (X**2) * (Y**2) * (Z**2)

Definition at line 116 of file check_time_order.py.

◆ phi_x

tuple check_time_order.phi_x = phi.deriv(0)

Definition at line 117 of file check_time_order.py.

◆ phi_y

tuple check_time_order.phi_y = phi.deriv(1)

Definition at line 118 of file check_time_order.py.

◆ phi_z

tuple check_time_order.phi_z = phi.deriv(2)

Definition at line 119 of file check_time_order.py.

◆ PX

check_time_order.PX

Definition at line 138 of file check_time_order.py.

◆ PY

check_time_order.PY

Definition at line 138 of file check_time_order.py.

◆ PZ

check_time_order.PZ

Definition at line 138 of file check_time_order.py.

◆ q

list check_time_order.q = [phi_y - phi_z, phi_z - phi_x, phi_x - phi_y]

Definition at line 120 of file check_time_order.py.

◆ U

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

Definition at line 132 of file check_time_order.py.

◆ U0

check_time_order.U0

Definition at line 130 of file check_time_order.py.

◆ V

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

Definition at line 133 of file check_time_order.py.

◆ V0

check_time_order.V0

Definition at line 130 of file check_time_order.py.

◆ VELOCITY_VARS

list check_time_order.VELOCITY_VARS = ["u", "v", "w"]

Definition at line 15 of file check_time_order.py.

◆ W

str check_time_order.W = f"{A}*{W0}"

Definition at line 134 of file check_time_order.py.

◆ W0

check_time_order.W0

Definition at line 130 of file check_time_order.py.

◆ x

check_time_order.x = Poly.var(0)

Definition at line 108 of file check_time_order.py.

◆ X

tuple check_time_order.X = (x + 0.5) * (1.0 - x)

Definition at line 113 of file check_time_order.py.

◆ y

check_time_order.y = Poly.var(1)

Definition at line 109 of file check_time_order.py.

◆ Y

tuple check_time_order.Y = (y + 0.5) * (1.5 - y)

Definition at line 114 of file check_time_order.py.

◆ z

check_time_order.z = Poly.var(2)

Definition at line 110 of file check_time_order.py.

◆ Z

check_time_order.Z = z * (1.0 - z)

Definition at line 115 of file check_time_order.py.