Commit 392a6c03 authored by Derek Thomas Steinmoeller's avatar Derek Thomas Steinmoeller

Merge branch 'ds/NHSW' into 'master'

Ds/nhsw

See merge request !1
parents 9d7fa5dc b45bd1d2
......@@ -73,12 +73,21 @@ BASECASE_OBJS := $(addprefix BaseCase/,$(notdir $(BASECASE_CPPS:.cpp=.o)))
SCIENCE_CPPS := $(wildcard Science/*.cpp)
SCIENCE_OBJS := $(addprefix Science/,$(notdir $(SCIENCE_CPPS:.cpp=.o)))
# Non-hydrostatic shallow water deps
NH_BASE := TArray.o Parformer.o T_util.o gmres.o gmres_2d_solver.o gmres_1d_solver.o Splits.o Par_util.o gmres.o grad.o multigrid.o chebmat.o
##
## Recipes
##
NSIntegrator.o: NSIntegrator.cpp NSIntegrator_impl.cc
NHchannel_x: NHchannel.o $(NH_BASE)
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
NHdonut2d_x: NHdonut2d.o $(NH_BASE)
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
tests/test%.o: tests/test%.cpp
$(MPICXX) $(CFLAGS) -o $@ -c $<
......
This diff is collapsed.
This diff is collapsed.
#include "chebmat.hpp"
using blitz::Array;
using blitz::TinyVector;
using blitz::GeneralArrayStorage;
using blitz::Range;
using blitz::firstDim;
using blitz::secondDim;
// Blitz index placeholders
//blitz::firstIndex ii;
//blitz::secondIndex jj;
//blitz::thirdIndex kk;
Array<double,2> chebmat(int Nx) {
blitz::firstIndex ii;
blitz::secondIndex jj;
Array<double,1> x(Nx);
x = cos(M_PI*ii/(Nx-1));
Array<double,2> myI(Nx,Nx);
Array<double,2> Dx(Nx,Nx);
Array<double,2> myX(Nx,Nx);
Array<double,1> myc(Nx);
Array<double,2> mydX(Nx,Nx);
Array<double,2> mysum(Nx,Nx);
// build identity matrix (any way to clean this up?)
for (int j=0; j<Nx; j++)
myI(j,j) = 1.0;
myc(0) = 2.0;
myc(Range(1,Nx-2)) = 1.0;
myc(Nx-1) = 2.0;
myc = myc*pow(-1.0,ii);
// like the "repmat" step - clean this up with blitz functionality?
for (int j=0; j<Nx; j++)
myX(Range::all(),j) = x;
mydX = myX-myX.transpose(secondDim,firstDim);
Dx = myc(ii)*(1/myc(jj)); //outer product
Dx = Dx/(mydX + myI);
// build diagonal matrix of row-sums
// perhaps try: sum(Dx(i,Range::all()))
double rowsum;
for (int i=0; i<Nx; i++) {
rowsum = 0.0;
for (int j=0; j<Nx; j++) {
rowsum+= Dx(i,j);
}
mysum(i,i) = rowsum;
}
Dx = Dx - mysum;
return Dx;
}
\ No newline at end of file
#pragma once
#include <blitz/array.h>
#include <math.h>
blitz::Array <double,2> chebmat(int Nx);
\ No newline at end of file
......@@ -249,6 +249,11 @@ void Cheb_2dmg::build_precond() {
// Now, get the Jacobian from grad_3d, carve off a relevant 2D slice, and
// assign it to the 2d gradient's jacobian.
double c_jac; // entry for constant jacobian
double myJ11=0.0, myJ22=0.0; //Derek: placeholders for constant jacobians.
// We assume these two are consts, and
// J12=J21= 0
// xx
grad_3d->get_jac(firstDim,firstDim,c_jac,v_jac);
if (!v_jac) {// constant
......@@ -358,6 +363,7 @@ void Cheb_2dmg::build_precond() {
/* J11 */
grad_2d->get_jac(firstDim,firstDim,c_jac,v_jac);
if (!v_jac) { // constant
myJ11 = c_jac; //Derek
t1 = c_jac;
t4 = 0;
} else {
......@@ -368,6 +374,7 @@ void Cheb_2dmg::build_precond() {
// J22
grad_2d->get_jac(thirdDim,thirdDim,c_jac,v_jac);
if (!v_jac) { // constant
myJ22 = c_jac; //Derek
t2 = c_jac;
t5 = 0;
} else {
......@@ -403,6 +410,18 @@ void Cheb_2dmg::build_precond() {
t2 = t2*t2 + (*v_jac)*(*v_jac);
}
//Derek: try generalizing it for any box-domain:
DTArray& helmCoef1 = *c1;
DTArray& helmCoef2 = *c2;
DTArray& helmCoef3 = *c3;
DTArray& helmCoef4 = *c4;
t1 = myJ11*myJ11*helmCoef2;
t2 = myJ22*myJ22*helmCoef4;
t4 = myJ11*helmCoef1;
t5 = myJ22*helmCoef3;
// Now, t1->t5 are set properly, so assign them to the MG operator
// fprintf(stderr,"PROBLEM SETUP\n");
// cerr << t1_2d << t2_2d << t3_2d << t4_2d << t5_2d;
......@@ -820,6 +839,23 @@ void Cheb_2dmg::set_bc(double h, double zdir, double zneum, S_EXP sym_type, doub
mg_precond->bc_setup(secondDim,dir_z,db_bot,da_bot,
dir_z,db_top,da_top);
}
// Derek method for setting the object's variable coefs. (all pointers)
void Cheb_2dmg::set_ci(DTArray * cin, int i) {
if (i==1)
c1 = cin;
else if (i==2)
c2 = cin;
else if (i==3)
c3 = cin;
else if (i==4)
c4 = cin;
else
fprintf(stderr,"set_ci\n");
return;
}
void Cheb_2dmg::precondition(fbox * & rhs, ubox * & soln) {
......@@ -930,6 +966,9 @@ void Cheb_2dmg::matrix_multiply(ubox * & lhs, fbox * & rhs) {
// return;
DTArray & dx = *temp1, & dz = *temp2;
//Derek: temporary for 2nd derivative.
DTArray& dd = *temp3;
Range all = Range::all();
// fprintf(stderr,"Matrix multiply\n");
......@@ -943,6 +982,17 @@ void Cheb_2dmg::matrix_multiply(ubox * & lhs, fbox * & rhs) {
grad_2d->get_dx(&dx);
grad_2d->get_dz(&dz);
DTArray& helmCoef1 = *c1;
DTArray& helmCoef2 = *c2;
DTArray& helmCoef3 = *c3;
DTArray& helmCoef4 = *c4;
// Derek: add first derivative terms to RHS
*rhs->gridbox = helmCoef1*dx + helmCoef3*dz;
//*rhs->gridbox = (*c1)*dx - (*c3)*dz; //Derek: Need minus if not
//doing setjac(-1,...) on
// z-coordinate.
// fprintf(stderr,"Dx\n");
// fprintf(stderr,"Dz\n");
......@@ -953,8 +1003,11 @@ void Cheb_2dmg::matrix_multiply(ubox * & lhs, fbox * & rhs) {
grad_2d->setup_array(&dx,SINE,NONE,CHEBY);
else
grad_2d->setup_array(&dx,type_x,NONE,CHEBY);
grad_2d->get_dx(rhs->gridbox);
// Derek:
grad_2d->get_dx(&dd);
*rhs->gridbox = *rhs->gridbox + helmCoef2*dd;
// lhs_zz
if (type_x == SINE)
grad_2d->setup_array(&dz,COSINE,NONE,CHEBY);
......@@ -962,7 +1015,10 @@ void Cheb_2dmg::matrix_multiply(ubox * & lhs, fbox * & rhs) {
grad_2d->setup_array(&dz,SINE,NONE,CHEBY);
else
grad_2d->setup_array(&dz,type_x,NONE,CHEBY);
grad_2d->get_dz(rhs->gridbox,true);
// Derek:
grad_2d->get_dz(&dd);
*rhs->gridbox = *rhs->gridbox + helmCoef4*dd;
// apply helmholtz
......
......@@ -81,6 +81,10 @@ class Cheb_2dmg : public GMRES_Interface < fbox * , ubox *> {
// used
DTArray * temp1, * temp2, * temp3;
//Derek: variable coefficients for more general problem
// c1 u_x + c2 u_xx + c3 u_z + c4 u_zz - u = f
DTArray * c1, * c2, * c3, * c4;
// C-ordered arrays for interfacing with the multigrid preconditioner
Array<double,2> * r2d, * s2d;
......@@ -137,6 +141,9 @@ class Cheb_2dmg : public GMRES_Interface < fbox * , ubox *> {
bool noisy() const;
// Derek: method for setting variable coefficients
void set_ci(DTArray * cin, int i);
private:
// Allocation data
vector<fbox *> r_free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment