Skip to content

Commit

Permalink
Merge pull request #21 from markcmiller86/mcm86-temp-remove-number-type
Browse files Browse the repository at this point in the history
Creating a PR into main to test mergeability
  • Loading branch information
markcmiller86 authored Jul 20, 2024
2 parents ad59ac4 + db6e79f commit 1a22ef7
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 255 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added .vscode/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}

48 changes: 48 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// Path to the Python interpreter
"python.defaultInterpreterPath": "/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/bin/python3",

// Use Pylance as the language server
"python.languageServer": "Pylance",

// Basic type checking mode
"python.analysis.typeCheckingMode": "basic",

// Automatically search for import paths
"python.analysis.autoSearchPaths": true,

// Use library code for types
"python.analysis.useLibraryCodeForTypes": true,

// Code Runner extension settings
"code-runner.executorMap": {
"python": "python -u"
},
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true,

// Enable linting
"python.linting.enabled": true,

// Use Ruff as the linter
"python.linting.ruffEnabled": true,

// Disable Pylint
"python.linting.pylintEnabled": false,

// Additional arguments for Ruff (empty in this case)
"python.linting.ruffArgs": [],

// File associations to specify how certain files are treated
"files.associations": {
"libfoo.C": "cpp",
"utils.C": "cpp",
"helloPy.C": "cpp",
"ftcs.C": "cpp",
"heat.C": "cpp",
"dufrank.C": "cpp",
"args.C": "cpp",
"crankn.C": "cpp",
"exact.C": "cpp"
}
}
121 changes: 0 additions & 121 deletions Number.H

This file was deleted.

31 changes: 31 additions & 0 deletions Number.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FPTYPE
#define FPTYPE 2
#endif

// 0=half, 1=float, 2=double, 3=quad
#if FPTYPE == 0
typedef _Float16 fpnumber;
#define FPFMT "%- .4g"
#define FPCAST double
#elif FPTYPE == 1
typedef float fpnumber;
#define FPFMT "%- .7g"
#define FPCAST double
#elif FPTYPE == 2
typedef double fpnumber;
#define FPFMT "%- .16g"
#define FPCAST double
#elif FPTYPE == 3
typedef long double fpnumber;
#define FPFMT ((sizeof(fpnumber)==10)?"%- .19Lg":"%- .34Lg")
#define FPCAST long double
#else
#error UNRECOGNIZED FPTYPE
#endif

#define Number fpnumber

#define TSTART -1
#define TFINAL -2
#define RESIDUAL -3
#define ERROR -4
129 changes: 78 additions & 51 deletions args.C → args.c
Original file line number Diff line number Diff line change
@@ -1,49 +1,76 @@
#include "heat.H"
#include "heat.h"

static char clargs[2048];

#define HANDLE_ARG(VAR, TYPE, STYLE, HELP) \
#define HANDLE_HELP(VAR, HELP, STYLE) \
if (help) \
{\
char tmp[256]; \
int len = snprintf(tmp, sizeof(tmp), " %s=%s(%s%s%s)", \
VAR, #STYLE, q, valstr, q);\
snprintf(tmp, sizeof(tmp), "%s", HELP); \
fprintf(stderr, " %s=%s(%s%s%s)%*s\n", \
VAR, #STYLE, q, valstr, q, 100-len, tmp);\
}\
else \
{ \
char tmp[64]; \
fprintf(stderr, " %s=%s(%s%s%s)\n", \
VAR, #STYLE, q, valstr, q);\
snprintf(tmp, sizeof(tmp), " %s=%s(%s%s%s)\n", \
VAR, #STYLE, q, valstr, q);\
strcat(clargs, tmp); \
}

#define HANDLE_FARG(VAR, HELP) \
{ \
char const *style = #STYLE; \
char const *q = style[1]=='s'?"\"":""; \
void *valp = (void*) &VAR; \
char const *q = ""; \
int const len = strlen(#VAR)+1; \
std::stringstream strmvar; \
char valstr[64]; \
for (i = 1; i < argc; i++) \
{\
int valid_style = style[1]=='d'||style[1]=='g'||style[1]=='s'; \
if (strncmp(argv[i], #VAR"=", len)) \
continue; \
assert(valid_style); \
if (strlen(argv[i]+len)) \
{\
if (style[1] == 'd') /* int */ \
*((int*) valp) = (int) strtol(argv[i]+len,0,10); \
else if (style[1] == 'g') /* double */ \
*((Number*) valp) = (fpnumber) strtod(argv[i]+len,0); \
else if (style[1] == 's') /* char* */ \
*((char**) valp) = (char*) strdup(argv[i]+len); \
}\
*((fpnumber*) valp) = (fpnumber) strtod(argv[i]+len,0); \
}\
strmvar << VAR; \
if (help) \
snprintf(valstr, sizeof(valstr), FPFMT, (double) VAR); \
HANDLE_HELP(#VAR, #HELP, float) \
}

#define HANDLE_IARG(VAR, HELP) \
{ \
void *valp = (void*) &VAR; \
char const *q = ""; \
int const len = strlen(#VAR)+1; \
char valstr[64]; \
for (i = 1; i < argc; i++) \
{\
char tmp[256]; \
int len = snprintf(tmp, sizeof(tmp), " %s=%s%s%s", \
#VAR, q, strmvar.str().c_str(), q);\
snprintf(tmp, sizeof(tmp), "%s (%s)", #HELP, #TYPE); \
fprintf(stderr, " %s=%s%s%s%*s\n", \
#VAR, q, strmvar.str().c_str(), q, 80-len, tmp);\
if (strncmp(argv[i], #VAR"=", len)) \
continue; \
if (strlen(argv[i]+len)) \
*((int*) valp) = (int) strtol(argv[i]+len,0,10); \
}\
else \
{ \
char tmp[64]; \
fprintf(stderr, " %s=%s%s%s\n", \
#VAR, q, strmvar.str().c_str(), q);\
snprintf(tmp, sizeof(tmp), " %s=%s%s%s\n", \
#VAR, q, strmvar.str().c_str(), q);\
strcat(clargs, tmp); \
} \
snprintf(valstr, sizeof(valstr), "%d", (int) VAR); \
HANDLE_HELP(#VAR, #HELP, int) \
}

#define HANDLE_SARG(VAR, HELP) \
{ \
void *valp = (void*) &VAR; \
char const *q = "\""; \
int const len = strlen(#VAR)+1; \
char valstr[64]; \
for (i = 1; i < argc; i++) \
{\
if (strncmp(argv[i], #VAR"=", len)) \
continue; \
if (strlen(argv[i]+len)) \
*((char**) valp) = (char*) strdup(argv[i]+len); \
}\
snprintf(valstr, sizeof(valstr), "%s", (char*) VAR); \
HANDLE_HELP(#VAR, #HELP, string) \
}

extern Number alpha;
Expand Down Expand Up @@ -80,11 +107,11 @@ static void handle_ic_help()
fprintf(stderr, " ic=\"step(L,Mx,R)\" a step function with value L for x<Mx and R for x>=Mx\n");
fprintf(stderr, " ic=\"rand(S,B,A)\" random values in the range [B-A,B+A] using seed S\n");
fprintf(stderr, " ic=\"sin(A,w)\" a sin wave with amplitude A and frequency w\n");
fprintf(stderr, " ic=\"spikes(C,A0,X0,A1,X1,...)\" a constant value, C with N spikes of amplitude Ai at position Xi\n");
fprintf(stderr, " ic=\"spikes(C,A0,X0,A1,X1,...)\" a constant value, C with spikes of amplitude Ai at position Xi\n");
fprintf(stderr, " ic=\"file(foo.dat)\" : read initial condition data from the file foo.dat\n");
fprintf(stderr,
"Be sure to use double-quotes (\") as shown and you may also need to set boundary"
"\nconditions such that they *combine* smoothly with the initial conditions.\n");
"\nconditions such that they *combine* smoothly with the initial condition.\n");
}

void
Expand All @@ -101,27 +128,27 @@ process_args(int argc, char **argv)
if (help)
fprintf(stderr, "Usage: %s <arg>=<value> <arg>=<value>...\n", argv[0]);

HANDLE_ARG(alpha, fpnumber, %g, material thermal diffusivity (sq-meters/second));
HANDLE_ARG(lenx, fpnumber, %g, material length (meters));
HANDLE_ARG(dx, fpnumber, %g, x-incriment. Best if lenx/dx==int. (meters));
HANDLE_ARG(dt, fpnumber, %g, t-incriment (seconds));
HANDLE_ARG(maxt, fpnumber, %g, >0:max sim time (seconds) | <0:min l2 change in soln);
HANDLE_ARG(bc0, fpnumber, %g, boundary condition @ x=0: u(0,t) (Kelvin));
HANDLE_ARG(bc1, fpnumber, %g, boundary condition @ x=lenx: u(lenx,t) (Kelvin));
HANDLE_ARG(runame, char*, %s, name to give run and results dir);
HANDLE_ARG(ic, char*, %s, initial condition @ t=0: u(x,0) (Kelvin));
HANDLE_ARG(alg, char*, %s, algorithm ftcs|dufrank|crankn);
HANDLE_FARG(alpha, material thermal diffusivity (sq-meters/second));
HANDLE_FARG(lenx, material length (meters));
HANDLE_FARG(dx, x-incriment. Best if lenx/dx==int. (meters));
HANDLE_FARG(dt, t-incriment (seconds));
HANDLE_FARG(maxt, >0:max sim time (seconds) | <0:min l2 change in soln);
HANDLE_FARG(bc0, boundary condition @ x=0: u(0,t) (Kelvin));
HANDLE_FARG(bc1, boundary condition @ x=lenx: u(lenx,t) (Kelvin));
HANDLE_SARG(runame, name to give run and results dir);
HANDLE_SARG(ic, initial condition @ t=0: u(x,0) (Kelvin));
HANDLE_SARG(alg, algorithm ftcs|dufrank|crankn);
#ifdef _OPENMP
HANDLE_ARG(nt, int, %d, number of parallel tasks);
HANDLE_IARG(nt, number of parallel tasks);
#else
HANDLE_ARG(nt, int, %d, parallel tasking is DISABLED!!);
HANDLE_IARG(nt, parallel tasking is DISABLED!!);
nt = 0;
#endif
HANDLE_ARG(savi, int, %d, save every i-th solution step);
HANDLE_ARG(save, int, %d, save error in every saved solution);
HANDLE_ARG(outi, int, %d, output progress every i-th solution step);
HANDLE_ARG(noout, int, %d, disable all file outputs);
HANDLE_ARG(prec, const int, %d, precision 0=half/1=float/2=double/3=long double)
HANDLE_IARG(savi, save every i-th solution step);
HANDLE_IARG(save, save error in every saved solution);
HANDLE_IARG(outi, output progress every i-th solution step);
HANDLE_IARG(noout, disable all file outputs);
HANDLE_IARG(prec, precision 1=float/2=double/3=long double)

if (help)
handle_help(argv[0]);
Expand Down
Loading

0 comments on commit 1a22ef7

Please sign in to comment.