Grid *ReadUserGrid() { Grid *user_grid; SubgridArray *user_all_subgrids; SubgridArray *user_subgrids; int num_user_subgrids; int i; num_user_subgrids = GetIntDefault("UserGrid.NumSubgrids", 1); /* read user_subgrids */ user_all_subgrids = NewSubgridArray(); user_subgrids = NewSubgridArray(); for(i = 0; i < num_user_subgrids; i++) { AppendSubgrid(ReadUserSubgrid(), user_all_subgrids); AppendSubgrid(SubgridArraySubgrid(user_all_subgrids, i), user_subgrids); } /* create user_grid */ user_grid = NewGrid(user_subgrids, user_all_subgrids); return user_grid; }
Subgrid *ReadUserSubgrid() { Subgrid *new_subgrid; int ix, iy, iz; int nx, ny, nz; int rx, ry, rz; ix = GetIntDefault("UserGrid.IX", 0); iy = GetIntDefault("UserGrid.IY", 0); iz = GetIntDefault("UserGrid.IZ", 0); rx = GetIntDefault("UserGrid.RX", 0); ry = GetIntDefault("UserGrid.RY", 0); rz = GetIntDefault("UserGrid.RZ", 0); nx = GetInt("ComputationalGrid.NX"); ny = GetInt("ComputationalGrid.NY"); nz = GetInt("ComputationalGrid.NZ"); new_subgrid = NewSubgrid(ix, iy, iz, nx, ny, nz, rx, ry, rz, -1); return new_subgrid; }
PFModule *KinsolNonlinSolverNewPublicXtra() { PFModule *this_module = ThisPFModule; PublicXtra *public_xtra; char *switch_name; char key[IDB_MAX_KEY_LEN]; int switch_value; NameArray switch_na; NameArray verbosity_switch_na; NameArray eta_switch_na; NameArray globalization_switch_na; NameArray precond_switch_na; public_xtra = ctalloc(PublicXtra, 1); sprintf(key, "Solver.Nonlinear.ResidualTol"); (public_xtra->residual_tol) = GetDoubleDefault(key, 1e-7); sprintf(key, "Solver.Nonlinear.StepTol"); (public_xtra->step_tol) = GetDoubleDefault(key, 1e-7); sprintf(key, "Solver.Nonlinear.MaxIter"); (public_xtra->max_iter) = GetIntDefault(key, 15); sprintf(key, "Solver.Linear.KrylovDimension"); (public_xtra->krylov_dimension) = GetIntDefault(key, 10); sprintf(key, "Solver.Linear.MaxRestarts"); (public_xtra->max_restarts) = GetIntDefault(key, 0); verbosity_switch_na = NA_NewNameArray("NoVerbosity LowVerbosity " "NormalVerbosity HighVerbosity"); sprintf(key, "Solver.Nonlinear.PrintFlag"); switch_name = GetStringDefault(key, "LowVerbosity"); (public_xtra->print_flag) = NA_NameToIndex(verbosity_switch_na, switch_name); NA_FreeNameArray(verbosity_switch_na); eta_switch_na = NA_NewNameArray("EtaConstant Walker1 Walker2"); sprintf(key, "Solver.Nonlinear.EtaChoice"); switch_name = GetStringDefault(key, "Walker2"); switch_value = NA_NameToIndex(eta_switch_na, switch_name); switch (switch_value) { case 0: { public_xtra->eta_choice = ETACONSTANT; public_xtra->eta_value = GetDoubleDefault("Solver.Nonlinear.EtaValue", 1e-4); public_xtra->eta_alpha = 0.0; public_xtra->eta_gamma = 0.0; break; } case 1: { public_xtra->eta_choice = ETACHOICE1; public_xtra->eta_alpha = 0.0; public_xtra->eta_gamma = 0.0; break; } case 2: { public_xtra->eta_choice = ETACHOICE2; public_xtra->eta_alpha = GetDoubleDefault("Solver.Nonlinear.EtaAlpha", 2.0); public_xtra->eta_gamma = GetDoubleDefault("Solver.Nonlinear.EtaGamma", 0.9); public_xtra->eta_value = 0.0; break; } default: { InputError("Error: Invalid value <%s> for key <%s>\n", switch_name, key); } } NA_FreeNameArray(eta_switch_na); switch_na = NA_NewNameArray("False True"); sprintf(key, "Solver.Nonlinear.UseJacobian"); switch_name = GetStringDefault(key, "False"); switch_value = NA_NameToIndex(switch_na, switch_name); switch (switch_value) { case 0: { (public_xtra->matvec) = NULL; break; } case 1: { (public_xtra->matvec) = KINSolMatVec; break; } default: { InputError("Error: Invalid value <%s> for key <%s>\n", switch_name, key); } } NA_FreeNameArray(switch_na); sprintf(key, "Solver.Nonlinear.DerivativeEpsilon"); (public_xtra->derivative_epsilon) = GetDoubleDefault(key, 1e-7); globalization_switch_na = NA_NewNameArray("InexactNewton LineSearch"); sprintf(key, "Solver.Nonlinear.Globalization"); switch_name = GetStringDefault(key, "LineSearch"); switch_value = NA_NameToIndex(globalization_switch_na, switch_name); switch (switch_value) { case 0: { (public_xtra->globalization) = INEXACT_NEWTON; break; } case 1: { (public_xtra->globalization) = LINESEARCH; break; } default: { InputError("Error: Invalid value <%s> for key <%s>\n", switch_name, key); } } NA_FreeNameArray(globalization_switch_na); precond_switch_na = NA_NewNameArray("NoPC MGSemi SMG PFMG PFMGOctree"); sprintf(key, "Solver.Linear.Preconditioner"); switch_name = GetStringDefault(key, "MGSemi"); switch_value = NA_NameToIndex(precond_switch_na, switch_name); if (switch_value == 0) { (public_xtra->precond) = NULL; (public_xtra->pcinit) = NULL; (public_xtra->pcsolve) = NULL; } else if (switch_value > 0) { (public_xtra->precond) = PFModuleNewModuleType( KinsolPCNewPublicXtraInvoke, KinsolPC, (key, switch_name)); (public_xtra->pcinit) = (KINSpgmrPrecondFn)KINSolInitPC; (public_xtra->pcsolve) = (KINSpgmrPrecondSolveFn)KINSolCallPC; } else { InputError("Error: Invalid value <%s> for key <%s>\n", switch_name, key); } NA_FreeNameArray(precond_switch_na); public_xtra->nl_function_eval = PFModuleNewModule(NlFunctionEval, ()); public_xtra->neq = ((public_xtra->max_restarts) + 1) * (public_xtra->krylov_dimension); if (public_xtra->matvec != NULL) public_xtra->richards_jacobian_eval = PFModuleNewModuleType( RichardsJacobianEvalNewPublicXtraInvoke, RichardsJacobianEval, ("Solver.Nonlinear.Jacobian")); else public_xtra->richards_jacobian_eval = NULL; (public_xtra->time_index) = RegisterTiming("KINSol"); PFModulePublicXtra(this_module) = public_xtra; return this_module; }
void wrfparflowinit_(char *input_file) { Grid *grid; char *seperators = " \n"; /* Fortran char array is not NULL terminated */ char *filename = strtok(input_file, seperators); /*----------------------------------------------------------------------- * Initialize AMPS from existing MPI state *-----------------------------------------------------------------------*/ if (amps_EmbeddedInit()) { amps_Printf("Error: amps_EmbeddedInit initalization failed\n"); exit(1); } /*----------------------------------------------------------------------- * Set up globals structure *-----------------------------------------------------------------------*/ NewGlobals(filename); /*----------------------------------------------------------------------- * Read the Users Input Deck *-----------------------------------------------------------------------*/ amps_ThreadLocal(input_database) = IDB_NewDB(GlobalsInFileName); /*----------------------------------------------------------------------- * Setup log printing *-----------------------------------------------------------------------*/ NewLogging(); /*----------------------------------------------------------------------- * Setup timing table *-----------------------------------------------------------------------*/ NewTiming(); /* End of main includes */ /* Begin of Solver includes */ GlobalsNumProcsX = GetIntDefault("Process.Topology.P", 1); GlobalsNumProcsY = GetIntDefault("Process.Topology.Q", 1); GlobalsNumProcsZ = GetIntDefault("Process.Topology.R", 1); GlobalsNumProcs = amps_Size(amps_CommWorld); GlobalsBackground = ReadBackground(); GlobalsUserGrid = ReadUserGrid(); SetBackgroundBounds(GlobalsBackground, GlobalsUserGrid); GlobalsMaxRefLevel = 0; amps_ThreadLocal(Solver_module) = PFModuleNewModuleType(SolverImpesNewPublicXtraInvoke, SolverRichards, ("Solver")); amps_ThreadLocal(solver) = PFModuleNewInstance(amps_ThreadLocal(Solver_module), ()); /* End of solver includes */ SetupRichards(amps_ThreadLocal(solver)); /* Create the flow grid */ grid = CreateGrid(GlobalsUserGrid); /* Create the PF vector holding flux */ amps_ThreadLocal(evap_trans) = NewVectorType(grid, 1, 1, vector_cell_centered); InitVectorAll(amps_ThreadLocal(evap_trans), 0.0); }